Me.NewRecord not being recognized

I am attempting to open a repair order to create an estimate for a customer who is having his/her vehicle worked on. the following is a sketch of the form that creates the invoice:

1. There is a parent form that allows the user to enter DateIn, DateOut, MilesIn, Miles Out, etc
2. There is a subform that permits the user to enter the parts needed for the repair.
3. There is a subform that allows the user to identify the items that need repair - turn rotors, oil change, replace front brake pads, etc.
4. This subform has the customer contact data and vehicle information.

It appears to be item 4 above that is giving me the trouble. When a new record is created, I want frmJobSub (Item 4 above) to automatically load the customer contact info and vehicle info. See code below. The result that I am expecting is that when the user clicks the button that opens the new invoice/record, I am expecting the test for a new record to  be true and the program to execute the If-Then code, but it is not.

Although I am looking at a new record, could someone please assist me in determining why the new record is not being recognized by the  program?

Thanks in advance.


Private Sub Form_Current()

 If Me.NewRecord Then 'And Not IsNull(lngpvtCustomerID) Then
        lngpvtCustomerID = Forms!frmCustomerContactData.CustomerID
        'Look up the cust fields
        Me.lblFullName = DLookup("FirstName", "tblMasterCustomer", "CustomerID=" & lngpvtCustomerID & " ")
        'Save these entries
        DoCmd.RunCommand acCmdSaveRecord
        'Clear the variable
        lngpvtCustomerID = Null
    End If

End Sub

Open in new window

Who is Participating?
mbizupConnect With a Mentor Commented:
Try populating the data in the desired fields from the event code that opens the form in stead of from the form itself.


  'Following your code that opens the form and goes to a new record...
Forms!YourFormName.lblFullName = DLookup("FirstName", "tblMasterCustomer", "CustomerID=" & me.CustomerID & " ")

yddadsjd95Author Commented:
Oh, I forgot to say that the DLookup function is only one of about a dozen lines of code that I need to put in the On Current event. I only placed one in there to test it. I'm trying to load some values into the new form when it opens.
Jeffrey CoachmanMIS LiasonCommented:

That code I posted presumed that the new record you were creating was on the same form as the form you are currently in...
...again, FWIW...

I am sure that mbizup can get you sorted...
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

yddadsjd95Author Commented:
You are correct Jeff, Once I get over this hurdle, I'll be able to follow the code that you gave me...hopefully :-).

Thank you mbizup, I'm working on it, but after placing the code on the object that calls the estimate-form (btnRepairOrder), I get the following error:

Run-time Error '2448'.
You can't assign a value to this object.

If I understood you and Jeff correctly, I placed the DLookup function on the button that opens the estime-form (frmJob, with a subform frmJobSub), and not in  frmJobSub).

yddadsjd95Author Commented:
I forgot the code, but after viewing the error message and going back to the code, I figured out why the object could receive a value: because it was a label instead of a text box.

Thanks for the help.
I was just about to submit a response, refreshed the screen and saw that you had worked this out.

Nice job!

I guess you figured out the "Caption" property for labels?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.