Error only on first record.

mafhobb

Registered User.
Local time
Today, 07:28
Joined
Feb 28, 2006
Messages
1,249
I have a small database with several forms. One of them has a command button to open a new form (which also contains a continuous subform) and go to a new record in the form. This is the code behind it:
Code:
    stDocName = "Main Data Entry"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    DoCmd.RunCommand acCmdRecordsGoToNew
This database has been in use for quite without problems a while but now I am doing a few small changes and cleaning it up of data to start over.

The code above gives the error "The command or action "RecordsGoToNew" isn't available now" yet it opens the form just fine and data can be entered. This error only happens when the first record is entered; it does not show up when entering the second or subsequent records.

Anyone know what is happening?

mafhobb
 
Maybe it's already in "new record" mode because the underlying table has no existing records?
 
It seems like Access should know how to deal with that???

How can I know for sure that this is the case?
 
I've often found that other DoCmd's relating to record operations aren't always as clever as you'd like them to be.

There must be a VBA-checkable property that would tell you that the form / underlying recordset is in "new record mode" but I don't know what it is off the top of my head.
 
Well, it seems like a cheese way to solve it but I basically captured the error number and told the code to ignore it. Not an elegant way to solve this but it works.

mafhobb
 
A fine contender for the January "Golden Spur" award. I would never have suggested that myself, of course :D
 
There must be a VBA-checkable property that would tell you that the form / underlying recordset is in "new record mode" but I don't know what it is off the top of my head.
Code:
If(Me.DataEntry = True)
, I believe.

Although I think if I understand the question correctly, the form is already in DataEntry mode and you want to check if this is already a new record. Me.NewRecord will get you that.
 
The form is not set for Data Entry mode. It is a form showing a record that can be edited or can be used to add a new record.
 
Something else must be going on to stop it from moving records, then. Have you tried:
Code:
Docmd.GoToRecord acDataForm,stDocName,acNewRec
 

Users who are viewing this thread

Back
Top Bottom