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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Button opening 2:nd form showing same record problem.

Status
Not open for further replies.

xollef

Technical User
Apr 23, 2002
30
Hi

I have a form with buttons on it. When i press a button it opens another form. I used the buttonwizard and created the button and there I linked the ID field that shows up on both forms so when pressing the button the other form opens with same record nr as in the "main form".

The problem is when the "main form" gets a new nr (autonumber). The buttons won't open the other forms anymore because they don't have the corresponding nr. So how do I solve this. When pressing the button and the nr isn't in the other form yet it should add it there and open.

I am using Access 2002 and I am not good at VB.
The code the wizard made is:
Private Sub Command106_Click()
On Error GoTo Err_Command106_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Viikkonaytteet_lammonjohtavuus"

stLinkCriteria = "[ID]=" & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command106_Click:
Exit Sub

Err_Command106_Click:
MsgBox Err.Description
Resume Exit_Command106_Click

End Sub
 
Well i solved this myself. I put the default value for the ID field that opens to be the same value as in the ID field of the "main form". so when i open the other form with the button the value in the id fields are always the same in both forms.

In the other form i chose property for the field there data tab and there default value i set it to be

=[Forms]![name of "main form"]![ID]

This seems to work fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top