Button to Open form to add new record with pre-filled field?

bazzanoid

Registered User.
Local time
Today, 15:00
Joined
Aug 30, 2008
Messages
35
Morning all,

I'm a bit rusty at the moment having been away from databases for some time, and now my job takes me back to them again... a quick question i'm stuck on if I may:

I'm working on a bookings database for school visits, and having got almost everything sorted, i have a few sticking points! The major one is pre-filling a field. Here's what I want to happen:

User clicks button on the Schools form (which, naturally, has the particular school details on), which opens a blank record on the Bookings form to create a new booking, but I want it to pre-fill the "School" field to avoid the wrong school being booked in - easily done with a few hundred on the list, a dozen or so sharing the same name except for Infants or Junior at the end! The "School" field comes from the Schools form, field name "School Name".

I know it can be done, I just can't think of how to do it for the life of me!:confused:

Thanks!

Barry
 
hi and welcome to the forums

search the forum for "openargs" it should solve your problem.
 
hi and welcome to the forums

search the forum for "openargs" it should solve your problem.


Did that, i get the theory behind it and the code etc, but access doesn't seem to. So, in the VB code sheet on access for the click event for that button i have entered:

Code:
DoCmd.OpenForm(Bookings,acNormal,,,acFormAdd,acWindowNormal,"School =" & Me.[School Name])

to which i'm greeted with

Compile error:
Expected: =

I've been trying to figure this "=" it wants for quite some time but with no joy!!!!
 
Could you not just use this on the button's ON CLICK event...

DoCmd.OpenForm "Bookings", acNormal, "", "", acAdd, acNormal
Forms![formtobeopened]![school] = Me.[School Name]

Hope this helps
 
OR,

set the default value of the field in your opening form to your desired field that is already open.

then, when your form is opened, it will pick up the value without any code.


NS
 

Users who are viewing this thread

Back
Top Bottom