Linking a form to another using a primary key

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form that has to have a button added. This button will open a pop
up data entry window. The data entry form has been created and is ready to
go. My problem is this, the form that will have the button has a Project_no
that ties alot of other tables and forms together, I need this number to
carry over to the Pop up Window that I've created. The primary key in the
Pop Up Window is the same (Project_no). I know it involves an ON OPEN
command, I just do not know Access that well. Can someone please give me
some advice on how to handle this problem.
 
I have a form that has to have a button added. This button will open
a pop up data entry window. The data entry form has been created and
is ready to go. My problem is this, the form that will have the
button has a Project_no that ties alot of other tables and forms
together, I need this number to carry over to the Pop up Window that
I've created.


in the first form:

private sub cmdOpenOtherForm_Click()

' .... etc

' Open the form, pass the projectno value...
' the brackets are optional, but can help with debugging
docmd.openform strOtherForm _
WindowMode:=acdialog, _
OpenArgs:= "[" & me!projectNo & "]"

' .... etc

end sub


and in the second form:

private sub Form_Open(Cancel as Integer)

dim strSQL as String

if isnull(me.OpenArgs) then
' can't call it without a project to look at
msgbox Me.Name & " called with no arguments!!"
cancel = true

else
' debugging: it really helps!
msgbox Me.Name & " called with: " & me.OpenArgs

' okay: create a recordsource
strSQL = "SELECT * FROM OtherTable WHERE ProjectNo = " & _
Mid(Me.Openargs, 2, len(me.openargs)-2)

' set the form to just one record
me.recorsource = strSQL

end if

' that's all there is
End Sub


Hope that helps

Tim F
 
Back
Top