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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a record using a form

Status
Not open for further replies.

cailo

Technical User
Sep 23, 2003
3
0
0
AU
Hi all. I know this is a stupid question but currently I have a database that allows you to add a record using a form. My issue is when I open the form up, there is already data in all my fields, so when I overwrite the fields the previous record is removed from my database. Is there a way to open the form with no records showing, just a blank form?
Cheers
Cailo
 
Cailo,

Are you opening the form from the database window or from another form?

If its from another form, create a command button and in the OnClick event procedure for that button put:


DoCmd.OpenForm frmName, , acNewRec


Where frmName is the name of your form.

If you want to open the form from the database window, type the following in the OnLoad event procedure for your form.


DoCmd.GoToRecord , , acNewRec


Good luck
 
thanks daklem but it didnt work. I am opening the form from another form. My code is as follows:

Private Sub Add_Record_Click()
On Error GoTo Err_Add_Record_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmAddRecord"
DoCmd.OpenForm stDocName, , acNewRec

Exit_Add_Record_Click:
Exit Sub

Err_Add_Record_Click:
MsgBox Err.Description
Resume Exit_Add_Record_Click

End Sub

Anymore ideas?
 
Thanks for your help daklem but i have figured it out. Im remembering stuff I learnt at school. I just set the form to Data Entry and all is good now :)

Thanks again
 
Just for future reference...

cailo, changing the Data Entry property of the form is the most direct method of always opening the form to a new record. That's fine if you don't need the ability to see other records in the same form. If you *do* want the other records available, then daklem was on the right track.

daklem, your code to go to a new record in the On Open event was exactly right. I believe the correct syntax for the OpenForm method in your example, though, is this:

Code:
DoCmd.OpenForm stDocName, , , , acFormAdd

At least it is in Access XP; can't say with regard to earlier versions.

HTH...

Ken S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top