Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forms: How to default to Add Record 1

Status
Not open for further replies.

jgi

Programmer
Dec 12, 2003
13
GB
I've got a Form that links with a Table that already has about 12,000 records in it. I am trying to use the Form simply as a pretty/user-friendly tool to make an addition to the Table and possibly to search for records. The Form itself is in Justified so that it only displays one record. When I open the Form, however, it displays the first record from the Table. I would like it to automatically default to adding a record, i.e. all fields blank. Any insight? Thanks.

jgi.
 
you can set the properties of the form to open up in add mode. that will result in the form opening up and all the fields being blank ready for data input.
 
The code below is what i use to open a form to add a new record


Private Sub CmdNewMem_Click()
On Error GoTo Err_CmdNewMem_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "YOURFORMNAME"
DoCmd.OpenForm stDocName, , , acNew

Exit_CmdNewMem_Click:
Exit Sub

Err_CmdNewMem_Click:
MsgBox Err.Description
Resume Exit_CmdNewMem_Click

End Sub

Hope this helps
Hymn
 
Hymn: Your code didn't work for me. I guess I need to know, like dgwillia said above, what code to put in the "On Open" Event Procedure. So dgwillia, if you have some code I'd love to see it.

Thanks for the quick responses.

jgi.
 
i have many forms that open in data entry mode without any code. I just change the forms properties. At the moment i do not have access to hand so i cant specifically say the exact option that need to be changed.

But for example i believe i change the data entry option to Yes and view records (not sure if called that) to no or depending what your preferences are.

there is no need for VB code to accomplish the task of cetting up a form to open up in add mode. just play around with the settings. when i can remember the exact settings taht need to be changed ill post back.
 
Ah... I see dgwillia. I only had to change one option in properties, Data/Data Entry - "Yes", and that did the trick. Okay, so that's taken care of - thank you. How, now, do I add a button that allows the user to save the record they've just entered and then subsequently clear the fields making the Form ready for a new entry?

I'm new to Access and this stuff is getting more and more fascinating as I work on it.
 
Er, I mean... how do a clear the fields after the Save button is clicked. Is there an option in the creation process for clearing the fields?
 
you can add a add record button to the form and when this is clicked that will clear all the fields ready for a new record to be added. Do this by adding microsoft access buttons and follow the wizard, then choose add record button.
 
With a little cut-and-paste of code, I got my Save button to save and clear the fields for a new entry. Thanks for all the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top