Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a form with the correct record id.

Status
Not open for further replies.

surfside1

Programmer
Feb 12, 2006
209
0
0
US
I've asked this before and got alot of good help, just nothing seems to get me past my problem.

I have a grid on a form, when someone clicks on a row, it should open a form with the contents of the record of that row. I have been able to pass the value of the grid ID with this:
Private Sub Open_frmListingEditForm()
Dim fListingEditForm As New frmListingEditForm
'fListingEditForm.SetReceive("Your ID value here")
fListingEditForm.SetReceive(intgridID)
fListingEditForm.ShowDialog()
End Sub
Then in the receiving form:
Public Sub SetReceive(ByVal Value As String)
txtReceive.Text = Value
IDTextBox.Text = Value
End Sub
Both fields txtReceive and IDTextBox are on the form. The txtReceive is not the ID of the record but IDTextBox is from the datasource. When the form opens, the txtReceive contains the correct value, but the IDTextBox contains the 1st record in the table and all the contents on the form belong to the 1st record.

Is there something else I need to do when opening the form to make sure it displays the correct record?

Also, if I want the form to open for new records (blank but just with a new ID from the autonum in the table, how do I do that?

I sure hope this makes sense, because it is so easy in Access, just can't figure it in VB. Thanks so much!
 
When I've had to this sort of thing in the past I normally take one of two actions. This first is when I have no class associated with my data I then add a new constructor to the form to accept my ID. This is then stored in a private member variable and then within the form's Load event I then get the information from the database and populate the form's controls with the results (assuming they're not bound)

On the other hand if I have a class for my data instead of passing an ID I pass instance of the class to be edited. So any changes made in the form are reflected in the underlying class.

All that's needed then is to refresh the calling form's view when the dialog is closed, and as you have a databound grid it should be a simple matter of .Refresh()

HTH
--


woogoo
 
I'm sorry, but I'm really new at VB. In Access this was really simple. My form's fields are bound to the data, so I was thinking that as long as I received the value of the ID in the ID field that is bound to the table, that it would bring up the form with that ID's values. Instead, the txtReceive.text which also receives the value does show the correct value on the form, the IDTextBox with is bound to the table defaults to the 1st id in the table. The following statements are how the fields receive the data:
Public Sub SetReceive(ByVal Value As String)
txtReceive.Text = Value
IDTextBox.Text = Value
End Sub

Do I need to code something in the Load routine also for the SetReceive sub?
 
I'm not to familiar with databound controls to be honest, so I can't say much more.

woogoo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top