Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I set a form in a module?

Status
Not open for further replies.
Feb 8, 2002
43
US
Below is a function that I'm writing in a module that will validate the info entered into my form. As Soon as I hit any code referring to the form variable, I get the error "Object variable or With block Variable not set".

I'm assuming its because I'm not setting the form object right. How do I do that?

Thanks.


Public Sub AreFieldsValid()

Dim Form As Form_Remittance
Dim db As Database
Dim rs As Recordset

Set db = CurrentDb()
Set rs = db.OpenRecordset("Remittance")



If Form.Remitter = "" Then
Form.Remitter.SetFocus
MsgBox "Enter a Remitter"
Else
End If
 
Thanks, but I know that you are supposed to used the Me keyword if you are using code in the immediate object but that is not what I am trying to do.

I am writing a global function from a module that I want to be able to call from multiple forms. How would I do that?

Thanks.
 
Screen.Activeform ??? I have no idea what I'm talking about
 
If you are in a module trying to refer to a form....you use

[Forms]![FormNAME]
 
I use this method for many global type functions.

Example:
Function fnCloseForm(frmA as Form)
...
...
DoCmd.Close acForm, frmA
...
...
End Function

Add the following to the forms event you want it tied to;

Call fnCloseForm(Me)

This would close the form you are on when the event is triggered.

If you want to refer to fields on the form in the Global function whereever you would normally use Me.FieldName substitute it with frmA.FieldName in the function.

Hope this helps.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top