Calling a form in variable

R

Richard

Hi all,

I have some code that I want to share between various forms. My code looks
like this in a single form:

If Me!txtRef = "" Then
Exit Sub
End If

Where txtRef is a text box value entered by users

So I created a public procedure

Public Sub TestRef (ByVal FormName as Form)
If FormName!txtRef = "" Then
Exit Sub
End If
End sub

Then from my form frmTest I created an on click event: Call TestRef(frmTest)

I receive a 424 execution error, Object required.

What's wrong with this ?

Thanks for your help

Richard
 
S

Stefan Hoffmann

hi Richard,

Where txtRef is a text box value entered by users

So I created a public procedure

Public Sub TestRef (ByVal FormName as Form)
If FormName!txtRef = "" Then
Exit Sub
End If
End sub
This makes no sense as the Exit Sub only affects the TestRef method, not
the calling one.
Then from my form frmTest I created an on click event: Call TestRef(frmTest)
I receive a 424 execution error, Object required.
You cannot pass an object as ByVal and the name of your variable is also
not well choose. This should work:

Public Function TestReference(ByRef AForm As Access.Form) As Boolean

TestReference = (AForm.Controls("txtRef") <> vbNullString)

End Function


mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top