Results 1 to 12 of 12

Thread: Select from a Listbox or MSHFlexGrid

  1. #1

    Thread Starter
    New Member Bagpiper's Avatar
    Join Date
    May 2005
    Location
    Missouri, USA
    Posts
    5

    Select from a Listbox or MSHFlexGrid

    Hi Team
    First let me say that I am so glad I found this forum. I have just spent the past hour browsing around. Very well done and very well supported.

    Visual Basic: Version 6
    Database: Access 97 format
    Connection: Adodc / Jet

    Problem.
    I am very new to VB6. Two weeks to be exact. I have created an access database. I can show either a single item, "Name" in a Listbox or several selected fields in an MSHFlexGrid.

    Is there a way to open the database record, to edit just the chosen record. So if I double click on a record half way down either the list box or MSHFlexGrid, it will open another form to edit that one record.

    Cheers
    Jim

  2. #2
    Addicted Member
    Join Date
    Jul 2004
    Location
    Mumbai
    Posts
    236

    Re: Select from a Listbox or MSHFlexGrid

    hi bagpiper,

    on the onclick event of the msHflexgrid get the selected row's primary id value. store the value in a global variable and load the form where u will retrieve the record based on the global variable. and fill the form for editing.

    -- Kishore..

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Select from a Listbox or MSHFlexGrid

    Welcome to the forum

    I'm not sure a global variable would be required - or actually preferred.

    The listbox or flexgrid item that is clicked is known to the control.

    So referring to the .ROW/.COL item of the flexgrid or the .SELECTED item of the listbox in the little form that is going to edit it.

    Make sure the form that does the edit is loaded MODAL - so that another row or item cannot be selected on the original form while the edit is being done.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4

    Thread Starter
    New Member Bagpiper's Avatar
    Join Date
    May 2005
    Location
    Missouri, USA
    Posts
    5

    Red face Re: Select from a Listbox or MSHFlexGrid

    Thanks for the replies.

    I have chosen to use the .row solution with the flexgrid. Now no matter what I click on I can get the record ID stored in column 0.

    How do I use this to open just that record though in a form please?

    I have a form I use to add new records and want to pull this same form but open at the correct record.

    I understand the concept just don't know how to impliment it.

    Many thanks team
    Jim
    Last edited by Bagpiper; May 28th, 2005 at 11:01 AM. Reason: Correction

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Select from a Listbox or MSHFlexGrid

    Hi Jim, welcome to VBForums!

    I would recommend creating a public sub in the "add record" forum which accepts a parameter specifying the record to edit, and this can be called from the grid form. Eg:
    VB Code:
    1. 'In the DoubleClick event of the grid:
    2.   frmEditRecord.ShowRecord MSFlexGrid1.TextMatrix(0, CLng(MSFlexGrid1.Row))
    3.  
    4.  
    5. 'In the form to edit records
    6. Public Sub ShowRecord (lRecordID as Long)  '(i guessed that the ID is numeric, you may need to change "Long" to "String", and remove the CLng above)
    7.  
    8.   'find/select the record here (how you do this depends on your current methods)
    9.  
    10.   Me.Show
    11.  
    12. End Sub
    (change MSFlexGrid1 to the name of your grid control, and frmEditRecord to the name of the form)

  6. #6

    Thread Starter
    New Member Bagpiper's Avatar
    Join Date
    May 2005
    Location
    Missouri, USA
    Posts
    5

    Red face Re: Select from a Listbox or MSHFlexGrid

    Quote Originally Posted by si_the_geek
    'find/select the record here (how you do this depends on your current methods)
    Hi Si
    Alas that is the other bit of the problem. I just don't have the basics to achieve that part of the problem. I know that once I am shown how to do this last part I will be fine.

    Please can you help

    I am off to see about getting some books out of Comp USA on this stuff.

    Thanks to everyone for my welcome too.

    Cheers and happy coding
    Jim

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Select from a Listbox or MSHFlexGrid

    ok, there are several ways to work with databases, what you need to do depends on what methods you are using.

    what method are you using to add the record?

    It's best if post your code, or attach your form if you are using a data control.

  8. #8

    Thread Starter
    New Member Bagpiper's Avatar
    Join Date
    May 2005
    Location
    Missouri, USA
    Posts
    5

    Smile Re: Select from a Listbox or MSHFlexGrid

    Hi Si
    Well, I went to the shops and found most of the books on Visual Basic are between $29.00 - $49.00. - I came home empty handed.
    I need to go over the books I have me thinks.

    I don't understand the questions that everyone is asking. I think I need to sit down and do a bit more reading first.

    Thanks to everyone who has tried to help but I really am at beginner level.

    I am enjoying this learning experience.

    Will be in touch soon team

    Cheers and happy coding
    Jim

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Select from a Listbox or MSHFlexGrid

    Thats fair enough, feel free to come back and ask questions any time you like.

    We have lots of people on this site who are very knowledgable and happy to explain things to you, and most of us don't mind "silly" questions or re-explaining things either - we've all been beginners at some point and realise how confusing all the terminology can be.

  10. #10

    Thread Starter
    New Member Bagpiper's Avatar
    Join Date
    May 2005
    Location
    Missouri, USA
    Posts
    5

    Re: Select from a Listbox or MSHFlexGrid

    Hi Team
    I just wanted to give you an update. I realise now that I needed to unbind the ADODC controls and learn a wee bit of SQL.
    I do not have this issue resolved but I am heading in the right direction. I have just learned how to sort the records by date, which was bugging me. Problem is that items bound to ADODC are easy to learn but, from my limited knowledge, seem to be very inflexible.

    Anyway, the learning process continues.
    Thanks again for your efforts in helping me out.
    Last edited by Bagpiper; May 31st, 2005 at 01:02 PM.
    Cheers and happy coding
    Jim

  11. #11
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Select from a Listbox or MSHFlexGrid

    You are definitely headed in the right direction. Bound controls hide so much of what goes on in the DB that you do not get a strong knowledge of SQL from it. And as soon as you want to do something outside the scope of the control it gets even harder.

    Good luck and keep posting back with questions

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Select from a Listbox or MSHFlexGrid

    Quote Originally Posted by Bagpiper
    Problem is that items bound to ADODC are easy to learn but, from my limited knowledge, seem to be very inflexible.
    100 zillion per cent correct.

    Have you looked at Beacon's database tut that is posted at the top of this forum section?

    In addition to that, there are numerous articles and such on writing SQL that you can find on the web.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width