0

I have an access database with two forms. When the form is opened I got a pop up saying acNewRec command is not available now. I can hit end or debug. If I hit end and manually re-open the form it works properly. It just gives the error eveytime the access is open. Any suggestions on how to fix this?

Private Sub form_load()
  DoCmd.Maximize
End Sub

Private Sub form_timer()
  [Clock1] = Now
End Sub

Private Sub form_open(cancel As Integer)
  DoCmd.GoToRecord , , acNewRec
End Sub

Private Sub virusscanopen_click()
  DoCmd.Close Form.me.Name
  DoCmd.OpenForm "IT DEPARTMENT VIRUS SCAN FORM"
End Sub

Private Sub SIGN_IN_SUBMIT_Click()
  Me.Refresh

  If IsNull([LAST NAME].Value) Or IsNull(grade.Value) Or IsNull(issue.Value) Or IsNull(office.Value) Then
    Msbox "PLEASE ENTER ALL DATA FIELDS", vbCritical, "IT DEPARTMENT CUSTOMER INFO"
  Else

    txtmessage = grade.Value + Space(1) + [LAST NAME].Value

    MsgBox "Thank you" + Space(1) + (txtmessage) + "!" + Space(1) + vbNewLine_ + "Have a great day!" + vbNewLine_ + "Someone will assist you shortly." + vbNewLine_, vbInformation, "IT DEPARTMENT CUSTOMER INFO"

    [Date].Value = Format(Now, "mm/dd/yyyy")
    [Time].Value = Format(Now, "hh:mm:ss AM/PM")

    DoCmd.GoToRecord , , acNewRec

    Me.Refresh
  End If
End Sub
1

The fact that the error message said "acNewRec command is not available now" should have directed you to the line DoCmd.GoToRecord , , acNewRec. The form's recordset is not guaranteed to be open and positioned correctly during the Form_Open() event, especially not always accessible via DoCmd methods. Documentation says otherwise, but experience shows that there are potential problems with relying on the recordset to be in a reliable state in Form_Open.

There are other ways to make the form automatically open on a new record. Try putting the same line of code within the Form_Load() event. Setting the form's Data Entry value to Yes allows only new records.

Not the answer you're looking for? Browse other questions tagged or ask your own question.