Pre populating a form with data?

  • Thread starter Thread starter Craig Armitage
  • Start date Start date
C

Craig Armitage

Hi,

I have a clients form and an Appointments form that obviously have
corresponding tables..

I want to put a button on the clients form that opens the appointments form
and pre-populates the "Client" field. The client field is an integer lookup
against the clients names.

How do I go about this?

i tried but failed miserably
 
Hi Craig

You can create a form showing appointments - ensure that the ID field is
shown on this form.

From the main form (also with the ID field in a control) yu can place a
button with an OnClick event like this

Private Sub ButtonName_Click()
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "FormToOpen"
stLinkCriteria = "[IDField]=" & Me![IDField]
DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub

Note
FormToOpen = the name of the form with the appointments
"[IDField]=" & Me![IDField] = the 1st ID is the name of the control on the
new form and the 2nd ( Me![IDField] ) is the name of the control on the
main form containing the ID field

BUT

If you already have 2 forms (both with the ID field somewhere) you can use
the wizard to create a button for you.
 
Hi Wayne,

Thanks for your reply. Unfortunately I think its the wrong way round. If i
read your code correctly, it opens an existing appointment with matching
criteria..

What I need is a way to get from the Customers form into a new appointment
form with just the customers ID pre-populated.

So lets say I have a Customer record for Mrs Jones... currently I can go to
a new appointment form and select her name from a drop-down and fill in the
rest. But it would be so much nicer if I could click on a "Make
Appointment" button in the customer form that opens the Appointments form
and creates a new record with her customerID pre-populated.

The main reason for me wanting to do this is that the customers table
currently has 3000+ records!



Wayne-I-M said:
Hi Craig

You can create a form showing appointments - ensure that the ID field is
shown on this form.

From the main form (also with the ID field in a control) yu can place a
button with an OnClick event like this

Private Sub ButtonName_Click()
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "FormToOpen"
stLinkCriteria = "[IDField]=" & Me![IDField]
DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub

Note
FormToOpen = the name of the form with the appointments
"[IDField]=" & Me![IDField] = the 1st ID is the name of the control on
the
new form and the 2nd ( Me![IDField] ) is the name of the control on the
main form containing the ID field

BUT

If you already have 2 forms (both with the ID field somewhere) you can use
the wizard to create a button for you.




--
Wayne
Manchester, England.



Craig Armitage said:
Hi,

I have a clients form and an Appointments form that obviously have
corresponding tables..

I want to put a button on the clients form that opens the appointments
form
and pre-populates the "Client" field. The client field is an integer
lookup
against the clients names.

How do I go about this?

i tried but failed miserably
 

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

Back
Top