JayRod722
JayRod722

Reputation: 11

How to get a form field to auto fill when a product is entered?

I am trying to get my form to populate the days needed for testing automatically when I enter a new record but it keeps erring out. I am very new to using VBA and Access 2016.

I have looked at some other examples that people have posted that work and cannot get it to work.
I am continually getting debugger.

Option Compare Database

Private Sub Fill_SKU_AfterUpdate()
    PopulateFields
End Sub

Private Sub PopulateFields()
    frmSerialTracerLog.Days_Used_For_Off_Test = DLookup("Days_Used_For_Off_Test", "tblTestDays", "Fill_SKU = '" & frmSerialTracerLog.Fill_SKU & "'")
End Sub

Upvotes: 1

Views: 40

Answers (1)

Gustav
Gustav

Reputation: 55816

You probably are referring to the current form, thus use Me:

Private Sub PopulateFields()
    Me!Days_Used_For_Off_Test.Value = DLookup("Days_Used_For_Off_Test", "tblTestDays", "Fill_SKU = " & Me!Fill_SKU.Value & "")
End Sub

Upvotes: 2

Related Questions