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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems opening form with a command button

Status
Not open for further replies.

bgibsonIYD

Technical User
Jun 18, 2001
28
US
I have a form "Main Address" and another form "Registration". On the "Main Address" form I have a button cmdRegister that I would like to open the "Registration" form with. I would like both forms to have the same NAME ID field, and have it carried over from the Main Address form. (As if i'm entering a persons name and then press the command button to register that person for the conference. I dont want the registration form to go anywhere else). I have the following code:

Private Sub cmdRegister_Click()
On Error GoTo Err_cmdRegister_Click
If IsNull(Me![NAME ID]) Then
MsgBox "Enter contact's information before registering them."
Else

DoCmd.OpenForm "Registration", , , "[NAME ID] = " & Me.NAME_ID
End If

Exit_cmdRegister_Click:
Exit Sub

Err_cmdRegister_Click:
MsgBox Err.Description
Resume Exit_cmdRegister_Click

End Sub

Where am I going wrong here?

Beth
**Learning Access**
 
the Docmd statement can only be used to sync to a particular record once its opened

So to make the text box equal something
do this
Open the form like normal
DoCmd.OpenForm "Registration"
then set the text box equal to soomething
forms!Registration.form![NAME ID] = me![NAME ID]

DougP, MCP

Visit my WEB site to see how Bar-codes can help you be more productive
 
The code appears to be good. The only questions I have are, is the nameid field a number? If its text then use quotes

"[NAME ID] = '" & Me.NAME_ID &"'"

and if there is no match example: a new registration then you will want to have under the registration forms name_id default value property
=forms!mainaddress![name_id] so it will fill in the name id

other wise I can't see why it shouldn't work
 
The NAME ID field is a number. Okay, now I have entered the =forms!Main Address![NAME ID] so it will fill in the name id, but when I go to enter a new record in the registration table I get the following error:

You cannot add or change a record because a related record is required in table 'Names'.

The NAME ID field is related in those tables. I have the table 'Names' (which is the source for the "Main Address" form) and the table 'Registration' (which is the source for the "Registration" form). The NAME ID field in the 'Names' table is an autonumber, and teh NAME ID field in the 'Registration' table is a number field. I have the relationship drawn from NAME ID in 'Names' to NAME ID in "Registration". It's a one to many relationship with referential integrity enforced.

Why am I receiving this error message, and how can I fix it?

Beth
**Learning Access**
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top