OpenArgs?

supmktg

Registered User.
Local time
Today, 16:35
Joined
Mar 25, 2002
Messages
360
I've read about 50 posts regarding passing a value from one form to another, and I Just don't get it!

I have a table of zipcodes which I use to autofill city and state fields. The Zipcode is entered into txtCoZip. If the zipcode is in the table it autofills, but if the zipcode is not in the table, a form opens to add it to the table. OpenArgs seems to be the answer to this, but I can't quite follow it all the way through. This is the code I'm using to open the form:

Code:
 DoCmd.OpenForm "frmAddZipcode", OpenArgs:=Me.txtCoZip

This is the code I'm using on the onOpen event of frmAddZipcode:

Code:
If Not IsNull(Me.OpenArgs) Then
Me.ZipCode = Me.OpenArgs
End If

I'm getting an error "you cannot assign a value to this object'.
What am I doing wrong?

Thanks,
Sup
 
There is nothing wrong with your code, I think the problem is with the position of your code in the frmAddZipcode form. If you try to set a control in the open event you will get an error. If you put your code in the 'On Current' event instead it should work.

Private Sub Form_Current()
If Not IsNull(Me.OpenArgs) Then
Me.ZipCode = Me.OpenArgs
End If
End Sub
 
Sup
Code:
DoCmd.OpenForm "frmAddZipcode", OpenArgs:=Me.txtCoZip

I have not seen this form of the OpenForm statement in VBA before - I would always have used -
Code:
DoCmd.OpenForm "frmAddZipcode" , , , Me.txtCoZip
 
Shifty,

Thank you!!! OnCurrent did the trick!

BTW Peter - OpenArgs:=Me.txtCoZip works

Thanks,

Sup
 

Users who are viewing this thread

Back
Top Bottom