How do I take data from a record and input it into a form?

M

Matt

I'm relatively new to access, and I'm creating a DB for my uncle. I've got
most things figured out but I'm stuck on an important detail.
I have a table that contains a single number(ie. 1000). Every time I open a
form titled daily log, I need to grab that number and put into a textbox on
the form, and then update the record by 1(ie. num + 1). I created a query
that grabbed the number and made the control source property for the textbox
equal to the query, yet when I open the form, all the textbox contains is
#Name?
Any ideas on what that means, and what I need to do to get that number to
display on the form?
Thanks for any help.
 
D

Dennis

The way I do this is to only do it when some other field on the form has been
edited which activates the form Dirty event. You can do it in the Form Load
event if you wish. You can use the following code in either event

Dim lNum As Long

lNum = DLookup("YourNumberFieldName", "YourTable")
YourField = CStr(lNum)
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE YourTable SET YourNumberFieldName = " & lNum + 1
DoCmd.SetWarnings True
 
M

Matt

Thanks Dennis. That worked great

Dennis said:
The way I do this is to only do it when some other field on the form has been
edited which activates the form Dirty event. You can do it in the Form Load
event if you wish. You can use the following code in either event

Dim lNum As Long

lNum = DLookup("YourNumberFieldName", "YourTable")
YourField = CStr(lNum)
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE YourTable SET YourNumberFieldName = " & lNum + 1
DoCmd.SetWarnings True
 
Top