code for form

hi there

Registered User.
Local time
Today, 17:54
Joined
Sep 5, 2002
Messages
171
hello everyone,

i was wondering how to get a form to open up to a new record each time the form is opened. right now, every time i open the form it displays the first record in the referenced table, and i have to click a "new record" control button to make a new entry. is there an easy VBA code to do this and where would i insert this code? any suggestions?

thanks all
 
Hello there Hi There,

Perhaps the easiest method: Copy the code behind your new record button and paste it into the On Open Event of your form.

Regards,
Tim
 
Or set the Data Entry property of the form to Yes.
 
thanks for the replies, but where do I find the On Open Event property on the form, or the Data Entry property. when i go to the design view of the form and right click to display properties it gives me the properties for the nearest control (e.g. text box, label,...etc). so, i'm guessing this isn't the right place to do this. i guess i should mention i'm not using a macro or VBA to open the form. i'm just clicking on the object from the dbase window, but i created a new control button on another form to open this form. i'm still not sure where to locate the On Open Event or Data Entry properties. any help would be greatly appreciated.

thanks everyone
 
H,

Assuming you're at the database window, assuming that my version of Access (2000) works like your version, and assuming I know what I'm talking about, try this:

Open your form -- the one you want to go to a new rec when it's opened -- in design view. Look at the form's upper left hand corner, just below the title bar (color strip at top). There's a gray square -- click on the square if there is not a black dot inside. (If your properties dialog box is not on screen, click the View pull down menu and click properties.)

Your properties dialog box should say "form" in the title bar. Click the tab that says Event. Scroll down to find the On Open event and click in the white area to activate it. Now click on the three dots on the same line and just to the right of the white area.

Click Code Builder at the dialog box that pops up. Click OK.

Up comes VBA, cursor flashing between the first and last lines of the On Open event procedure for your form. Code placed between these two lines runs when the form opens.

For the data entry property, go to the Data tab of the form's properties dialog. Scroll down if necessary to find the Data Entry property -- it is set to No by default. Setting it to Yes will allow you to only add records, with no editing of records already saved.

Regards,
Tim
 
Last edited:
thank you Tim that worked perfectly and your instructions were EXTREMELY clear. thanks for also explaining the data entry property option. i must be able to edit records in the form view, so using your method was exactly what i needed to do.

thanks again
 
Glad to hear it -- thanks for your many thanks.

Regards,
Tim
 

Users who are viewing this thread

Back
Top Bottom