Passing Formname to a sub

JANR

Registered User.
Local time
Today, 01:10
Joined
Jan 21, 2009
Messages
1,623
I have a form which is is used to lookup customer information. This form is open in dialog mode so my users can select the correct customer and transfer data to my dataentry form. The problem I have is that this form should be availible on other forms, so in the OpenArg's argument I pass the calling forms name and would like to use this name in a With-block.

Currently I have this code behind the form:

Code:
Option Compare Database
Option Explicit
 
Dim CallForm As String
 
Private Sub cmdOverfør_Click()
PassCustomerData
End Sub
 
Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
    CallForm = Me.OpenArgs
End If
End Sub
 
Private Sub PassCustomerData()
With Forms![COLOR=red]frmNySak
[/COLOR]    !Kunde = Replace(Me!FIRMA, Chr(34), "")
    !Adresse = Replace(Me!ADR1, Chr(34), "")
    !POSTSTED = Left$(Me!POSTSTED, 4)
    !epost = Me!E_POST
    !merknader.SetFocus
End With
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub

I tried to use

Code:
With Forms! & CallForm
      ....
End With

But got an error on datatype mismatch.

The code works with the hard coded formname, but it isen't flexible enough, anybody

JR
 
Try

With Forms(CallForm)
 
Thanks Paul, worked like a charm.

JR
 
Happy to help JR.
 
For others who might stumble accross this tread, it helps to look in the help files.

The usual way I use to refer to open forms is:

Forms!FormName

but the 2 other ways are:

Forms("Formname") or Forms(Indexnumber)

JR
 

Users who are viewing this thread

Back
Top Bottom