Default Value for a Text box field

  • Thread starter Thread starter KM
  • Start date Start date
K

KM

It's something that's probably pretty simple for most... so I would
appreciate any help or guidance.

I have a form with a number of fields. I'm using a dlookup function to
bring in a value from another table based on what is entered in the fields
above. If I put the dlookup function in the control source within the text
box options, the right values come trough. My issue is that I want to edit
those values. If I put the same code in the default within the properties, I
either get an error, or nothing comes back.

How could I be able to have the text box on the form populate automatically
based on what's entered in previous fields, and then be able to change the
value if I needed to.

=DLookUp("[VendorName]","[MainTable]","[StoreNumber]=Forms![InvoiceTracking_frm]![StoreNumber]")
 
It's something that's probably pretty simple for most... so I would
appreciate any help or guidance.

I have a form with a number of fields. I'm using a dlookup function to
bring in a value from another table based on what is entered in the fields
above. If I put the dlookup function in the control source within the text
box options, the right values come trough. My issue is that I want to edit
those values. If I put the same code in the default within the properties, I
either get an error, or nothing comes back.

How could I be able to have the text box on the form populate automatically
based on what's entered in previous fields, and then be able to change the
value if I needed to.

=DLookUp("[VendorName]","[MainTable]","[StoreNumber]=Forms![InvoiceTracking_frm]![StoreNumber]")

This will just display the looked-up value. Since you need to edit it (in this
table, leaving it unchanged in the MainTable I presume!) you'll need to "push"
it into the textbox.

To do this you'll need to use the AfterUpdate event of (in this case, I'm
guessing) the StoreNumber control. Something like

Private Sub StoreNumber_AfterUpdate()
If IsNull(Me!yourcontrolname) Then ' don't stomp on already entered value
Me!yourcontrolname = DLookUp(... <your expression above>...)
End If
End Sub

If you do want to overwrite the user entered value when a new store number is
selected, omit the If and End If lines.
 
Back
Top