Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing parameters between forms in MS Access

I have created a login form named login where the username is typed into the txtEmployee textbox, and I need to display the same in the second page in another form in MS Access.

like image 701
user419263 Avatar asked Aug 13 '10 06:08

user419263


2 Answers

DoCmd.OpenForm allows you to pass an arbitrary value as the last parameter. This value can be accessed in the new form as Me.OpenArgs:

' Invoked by some Button on the first form '
Sub GoToSecondPage()
    DoCmd.OpenForm "MySecondPage", acNormal, , , , , txtEmployee.Value
End Sub

' Second form '
Sub Form_Open(Cancel As Integer)
    If Not IsNull(Me.OpenArgs) Then
        lblShowEmployeeName.Value = Me.OpenArgs
    End If
End Sub

(Code example untested.)

like image 179
Heinzi Avatar answered Sep 21 '22 08:09

Heinzi


You can pass a delimited string as the OpenArgs parameter:

DoCmd.OpenForm FormName:="miscForm", OpenArgs:=paramstring

Here's a routine for processing a pipe-delimited string passed as the parameter to DoCmd.OpenForm:

Dim Pstring As Variant

If Len(Me.OpenArgs) > 0 Then
   Pstring = Split(Me.OpenArgs, "|")
   var1 = Pstring(0)
   <etc..>
End If
like image 38
Lance Roberts Avatar answered Sep 17 '22 08:09

Lance Roberts