Opening a form with a new record

retro

Registered User.
Local time
Today, 14:13
Joined
Sep 5, 2003
Messages
69
I have a switchboard form that opens with the database. One of the buttons on it opens up a standard form for entering names and addresses.

I created the button with the button wizard, so the standard code:

Code:
    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "Enter Details"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

However, this opens the form with record 1 loaded. There is a danger that someone might accidentally enter data over that, so I would like it to open up to a blank record (at the moment, users have to know to press the ">*" button). How can I do this?

Thanks in advance for any help... and for putting up with me of late! ;)
 
Searching the forum is a great way to discover and learn the answers to your Access programming questions.

There are many options to do what you want. One way would be to open the form to a new record, like this...

Code:
DoCmd.OpenForm "Enter Details", , , , acFormAdd
You should also protect the users [and the data]. I suggest you look at these two threads and see how I control what a user can do and how I force them to either save or undo their changes before they can save the record or close the form. Check these links out for more info and samples...

A Better Mouse Trap?

Enable/Disable The Control Box X Button

The forms Before Update event is the key to data validation at the form level.
 
Thanks for your reply.

I totally agree, the search is great! I have learnt a lot from looking at samples - best way, I think! However, I couldn't find much relevant in this case (might have been poor search words on my behalf), and what I did find didn't work!

I should have mentioned, I already tried acFormAdd. This doesn't seem to work. In my database, I have 6 records to test it. So obviously, I want it to open on record 7. However, when I put acFormAdd in, it opens up the correct form, and it is indeed blank, but it says record 1 of 1. This isn't what I want - I want it to be on record 7, and to be able to view and edit the original records by clicking back.

The links you gave looked great - makes you see things you never thought of (well, I hadn't anyway!). Many thanks for that. I will look at your code with great interest :) Incidentally, I noticed at least one said for Access 97 - are they still just as relevant on 2003?
 
Make sure that the "Data Entry" property is turned off in the form.

Yes, my examples will convert and work in Access 2003.
 
Yeah, Data Entry is off on both the Switchboard form and the one I want to open.

The form opens fine manually, it is just when I use the button on the switchboard, which uses DoCmd.OpenForm with acFormAdd. It also works fine when I use acFormEdit, which led me to believe that acFormAdd wasn't the option I wanted (I'd played around with it before even checking the forum).

Have I done something wrong here? :\
 
Ahh yes, if I put that in the Form Load of the Form with the records, it works great! Thanks, wazz! :)
 

Users who are viewing this thread

Back
Top Bottom