Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "SummaryForm"
stLinkCriteria = "[staffid] = " & Me![STAFFIDPK]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Docmd.Openform "SummaryForm",,,"[StaffID] = " & Forms!MyFormName!StaffIDPK & ""
I personally like to use the Forms!MyFormName!FieldName versus me!FieldName just to make sure the field is grabbed from the correct form. I also like doing the 1 line of code versus dim variables and 5 lines of code.
You really shouldn't need more complex link but maybe I'm missing something you're trying to do. But try out the statement above to see if that helps first. Just make sure that the StaffID field exists on the one form and StaffIDPK exists on the other form (ie. the field is actually on the form. It can be invisible/disabled/etc... but it should be on the form.)
You can also add in this line of code before your docmd.openform.... statement
msgbox "Staff ID = " & Forms!MyFormName!StaffIDPK
just to make sure that you don't have a blank StaffID when opening the second form.
You can also put criteria in the recordsource query of the 2nd form...ie...the sql statement would look like this if you viewed the code versus the query design: "Select * from MyTable where StaffID = " & Forms!MyFirstFormName!StaffIDPK & ""
Then you would only need to open the form without the criteria in the docmd.openform....
You'll should also test StaffIDPK that it is not blank (null) before the docmd.openform....
if not isnull(me!StaffIDPK) then
msgbox "Cannot open form with a blank StaffIDPK"
I'm also assuming that StaffID and StaffIDPK are integer (number) fields and there is a relationship between these 2 fields in the relational design.
Last edited by pkstormy; 11-21-08 at 22:27.
Expert Database Programming
MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)