0

I have an Access form with a text box named Box1.

In this text box, I want to have the name of the last product in my table Products as the default value.

My table product has the fields: P_ID and P_Name.

I have coded in VBA in the form:

Me!Box1.DefaultValue = DLookup("P_Name", "Products", "P_ID = DMax("P_ID", "Products")")

However, there is an error in my code as the textbox displays #Name.

Gustav
  • 53,498
  • 7
  • 29
  • 55
Acces124
  • 1
  • 3

1 Answers1

0

The DefaultValue property is a string, so quotes are needed:

Me!Box1.DefaultValue = "'" & DLookup("P_Name", "Products", "P_ID = " & DMax("P_ID", "Products") & "") & "'"
Gustav
  • 53,498
  • 7
  • 29
  • 55