There are several ways to do this. I'm giving you the one that is most
generic.
The following code is based on having the following elements:
Form - frmCustomer
Text Box - txtCustomerID
CommandButton - cmdBookings
Form - frmBookings
Text Box - txtCustomerID
Paste the following routine into the module for frmCustomer. It will
run when the button is clicked.
' Code Begin
Private Sub cmdBookings_Click()
On Error GoTo Err_cmdBookings_Click
' This is the important line
DoCmd.openform "frmBookings", , , , acFormAdd, ,
CStr(txtCustomerID)
Exit_cmdBookings_Click:
Exit Sub
Err_cmdBookings_Click:
MsgBox Err.Description
Resume Exit_cmdBookings_Click
End Sub
' Code End
Most of the above routine is error handling. The important line is
marked. This routine opens the form called frmBookings to a new
record, passing your CustomerID to frmBookings as an argument.
DoCmd.OpenForm has lots of options you can use to get what you want.
See Access' help for this command to tweak it to fit your needs.
The other half of this is that frmBookings needs to use the
CustomerID. Paste the following routine into the module for
frmBookings.
' Code Begin
Private Sub Form_Load()
txtCustomerID = Me.OpenArgs
End Sub
' Code End
This routine reads the ID passed by OpenForm and puts it into the text
box. If you want to add more than one record, you may want to move
this to the FormCurrent event instead of FormLoad, which will only set
the first record.
Additional Resources:
See Access Help for DCmd.OpenForm and OpenArgs.
Good luck with your Access project!
- Hammer |
Clarification of Answer by
hammer-ga
on
01 Apr 2003 05:12 PST
Note: The Answer Box may cause lines to wrap. No line of code in the
above routines should wrap.
- Hammer
|
Request for Answer Clarification by
mattie54-ga
on
01 Apr 2003 12:17 PST
Hi, thanks for your answer. I tried this but no data appears in the
field on the second form. Do I need to edit the data source for this
field?
Thanks, matt
|
Clarification of Answer by
hammer-ga
on
01 Apr 2003 12:38 PST
At this point, there could be any number of things wrong. You may have
the code in the wrong place. You may have things named differently,
etc... Could you post your database online somewhere that I can
download it and look for the problem?
Make especially sure that you have updated the code to match whatever
your forms and controls are actually named.
Let me know if you can post your database.
- Hammer
|
Request for Answer Clarification by
mattie54-ga
on
03 Apr 2003 04:01 PST
Hi, its working!! I had a final mess around with it as I was uploading
it and it started working! Thanks very much for your help. I may have
some other questions for you very soon! Please look out for them!
thanks for your help, matt
|
Clarification of Answer by
hammer-ga
on
03 Apr 2003 04:43 PST
I'm glad you got it working. I'll keep an eye out for your other questions.
- Hammer
|
Request for Answer Clarification by
mattie54-ga
on
03 Apr 2003 07:58 PST
New question! "Access database - help needed"
your help would be appreciated! and i will tip if you get it working!
just dont want to put too much money on it in case I get an answer
which I can't understand!!
cheers, matt (project is almost finished :-))
|
Clarification of Answer by
hammer-ga
on
03 Apr 2003 08:34 PST
I'll go look for it.
- Hammer
|