Continuous form Button to Open Specific Record

fractals

New member
Local time
Yesterday, 16:51
Joined
Jun 8, 2009
Messages
2
Hello.

I have a continuous form with an open button on each record that will open the details for the record listed. I am using the following code onthe event that the button is clicked:


>>
Private Sub Command177_Click()
Dim LName As Variant
Dim Last As Variant

If Nz(Me!Last, "") <> "" Then
Last = DLookup("ID", "Students", "[Last Name] = '" & Me!Last & "' ")
DoCmd.Close
DoCmd.OpenForm "Student Details", acNormal, , "ID=" & Last

End If
End Sub
<<

Works except it only opens the first record on the continuous form, not the one the button is on. I have searched for an hour to find an answer. Please help!
 
Have you set a breakpoint or otherwise confirmed that Last contains what you expect?
 
i think you should put the

DoCmd.OpenForm "Student Details", acNormal, , "ID=" & Last code first before

DoCmd.Close because you are closing the form where you are getting your variable.
 
That's a good point, and it is good practice, but in my experience the code will still work even with the Close first.
 
Last = DLookup("ID", "Students", "[Last Name] = '" & Me!Last & "' ")

why do this? there may be several students with the same last name - just store the ID field on the continuous form (hidden or grayed out if you like)
 

Users who are viewing this thread

Back
Top Bottom