We help IT Professionals succeed at work.
Get Started

New Record command not firing

skull52
skull52 asked
on
207 Views
Last Modified: 2016-02-11
I have a save button on my access form that first validates that all required fields are filled in and if so to save the record and go to a new record, but the new record portion of my code doesn't seem to fire. I have attached my code
Private Sub btnSave_Click()
'If MsgBox("Do you want to SAVE the record (or the change)", vbYesNo, "Save Record...") = vbNo Then
'        Me.Firstname.SetFocus
'        Me.Company.SetFocus
'       Me.Undo
'      Cancel = True
' Validates that Control has Data for required feilds
If Len(Firstname) = 0 Or IsNull(Firstname) = True Then
  Call MsgBox("You must enter First Name", vbExclamation, "Add Firstname")
  Me.Company.SetFocus
  Me.Firstname.SetFocus
   Cancel = True
ElseIf Len(Lastname) = 0 Or IsNull(Lastname) = True Then
  Call MsgBox("You must enter Last Name", vbExclamation, "Add Lastname")
  Me.Company.SetFocus
  Me.Lastname.SetFocus
   Cancel = True
ElseIf Len(Address1) = 0 Or IsNull(Address1) = True Then
  Call MsgBox("You must enter Address1", vbExclamation, "Add Address1")
  Me.Company.SetFocus
  Me.Address1.SetFocus
   Cancel = True
ElseIf Len(City) = 0 Or IsNull(City) = True Then
  Call MsgBox("You must enter City", vbExclamation, "Add City")
  Me.Company.SetFocus
  Me.City.SetFocus
   Cancel = True
ElseIf Len(State) = 0 Or IsNull(State) = True Then
  Call MsgBox("You must select a State", vbExclamation, "Add State")
  Me.Company.SetFocus
  Me.cboState.SetFocus
   Cancel = True
ElseIf Len(Zip) = 0 Or IsNull(Zip) = True Then
  Call MsgBox("You must enter a Zip", vbExclamation, "Add Zip")
  Me.Company.SetFocus
  Me.Zip.SetFocus
   Cancel = True
ElseIf Len(Phone) = 0 Or IsNull(Phone) = True Then
  Call MsgBox("You must enter a Phone No", vbExclamation, "Add Phone")
  Me.Company.SetFocus
  Me.Phone.SetFocus
   Cancel = True
ElseIf Len(cboCSR) = 0 Or IsNull(cboCSR) = True Then
    Call MsgBox("You must select a CSR", vbExclamation, "Add CSR")
    Me.Company.SetFocus
    Me.cboCSR.SetFocus
   Cancel = True
ElseIf Len(cboMod) = 0 Or IsNull(cboMod) = True Then
    Call MsgBox("You must select a Model", vbExclamation, "Add Model")
    Me.Company.SetFocus
    Me.cboMod.SetFocus
   Cancel = True
ElseIf Len(Serial) = 0 Or IsNull(Serial) = True Then
    Call MsgBox("You must select a Serial Number", vbExclamation, "Add Serial")
    Me.Company.SetFocus
    Me.Serial.SetFocus
ElseIf Len(ProblemDesc) = 0 Or IsNull(ProblemDesc) = True Then
    Call MsgBox("You must select a Problem Description", vbExclamation, "Add ProblemDesc")
    Me.Company.SetFocus
    Me.ProblemDesc.SetFocus
 'Save the record.
    RunCommand acCmdSaveRecord
    'Load a new record after the save.
    DoCmd.GoToRecord , , acNewRec

 End If
'End If
End Sub

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2014
Commented:
This problem has been solved!
Unlock 1 Answer and 22 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE