Results 1 to 10 of 10

Thread: pass ID from 1 form to another

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    137

    pass ID from 1 form to another

    I have a datagrid, when the user clicks on a row, I want to direct the user to another form that displays the data selected as a single record..

    How do I retrieve the ID field from the row selected in the datagrid..so that I can get all the tables that relate to that ID number on the new form??

    THANK YOU

  2. #2
    Lively Member
    Join Date
    May 2001
    Posts
    95
    Do you have a key in the data or are you going to use the actual row ID as your key. You may want to have the key in your data and then hide that field so the user does not see it. Then you can key off that field.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    137
    the record has a primary key i.e. the customerID....

    isn't there some way of recording the customerID of the record selected and using that in the next form in a query to retrieve the required tables????

  4. #4
    Lively Member
    Join Date
    May 2001
    Posts
    95
    you would use code something like this.

    me.DataGrid1.Text

    this will retrieve the text value of the row and column you selected. However, if there are several columns in your data you will need to specify which col you are looking for. It has been a while since I did this but if your key is in the 3rd column over you would first set the column like:

    me.datagrid.col = 2 (I believe that datagrid columns start at 0)

    Then you would do

    me.datagrid1.text which would give you your value.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    137
    yeah k...fink i get what ur sayin...but i need to call that value on another form...how do I do that????

  6. #6
    Lively Member
    Join Date
    May 2001
    Posts
    95
    There are several ways to do this but here is one way.

    Lets say you have two forms. Form1 has the datagrid and form2 is the form you want to use once you get the value from your datagrid.

    Private Sub DataGrid1_Click()
    form2.Show
    form2.TextBox = Form1.DataGrid1.Text
    End Sub


    Now you have form2 open and you have the value. I don't know exactly what you want to do on form2 so I hope this helps

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    137
    thanks m8...il have a go and then let you no

  8. #8
    Lively Member
    Join Date
    May 2001
    Posts
    95
    You could also create a vaiable in Form2

    Public sVal as string


    then when the user clicks the datagrid on Form1:

    Private Sub DataGrid1_Click()
    form2.Show
    form2.sVal = Form1.DataGrid1.Text
    End Sub

    Now you have the variable stored in sVal

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    137
    next problem...im trying to retreive the data from the table in the database... I want it to be shown in text boxes.... so what I used is the properities at the side to create a DataSource and assign a datafield to each text box.....

    the problem is I don't no where to put the sql query...just now it returns the data of the first record....not of the selected row. (I've been able to send the value to the next page)....I just don't know where to put the query!!! can you help???

  10. #10
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    you may want to make this a new thread so people don't confuse it with the duplicates that you posted.


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