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!

Yet another problem with opening a form at a new record...

Status
Not open for further replies.

CantDo

Technical User
Jun 5, 2005
48
0
0
CA
I've read a lot about others having this problem, but none of what I've read is helping me with my problem. I have a main menu form which opens at startup. On that form is a button which is supposed to open another form for a new record. The code behind the Click event for this button is as follows:

Code:
On Error GoTo Err_AddButton_Click

    Dim stDocName As String
    stDocName = "DataForm"
    DoCmd.OpenForm stDocName, , , , _
    acFormAdd
    DoCmd.GoToRecord , , acNewRec

Exit_AddButton_Click:
    Exit Sub

Err_AddButton_Click:
    MsgBox Err.Description
    Resume Exit_AddButton_Click

There is also a listbox showing pre-existing data on the main menu. If I click the AddButton without first choosing a record in the listbox, I get an error (2051), however, if I first choose a value in the listbox, everything works as it should. Is there a simple way for me to get the AddButton to work whether or not I choose a listbox value?

FYI, the form DataForm is not used exclusively for new records but also to view and edit existing records.

Thanks in advance!
 
Ignore this post. I got it to work now. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top