Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dlookup access 2010 1

Status
Not open for further replies.

vba317

Programmer
Mar 5, 2009
708
US
I am trying to implement a dlookup command from the on enter event

The form name is frmServiceCalls
The Table name is tblAQM1data that I am getting the data from
The name of the of the text box on the form if txtSerialNumber
I am trying to populate a textbox called txtHospitalname on the form frmServiceCalls
I am not getting a error but the textbox hospitalname is not populating


I am using the following code

Code:
variable = DLookup("txtHospitalName", "TblAQM1Data", "[txtSerialNumber]=Forms![frmServiceCalls]!.[SerialNumber]")


[Code]
 
The part in Red is supposed to be the name of the Field in the Table, while the part in Blue is supposed to to be the name of the Control in the Form.

"[txtSerialNumber]=Forms![frmServiceCalls]!.[SerialNumber ]")

Given the names, it would appear as if you have reversed these.

This syntax is only valid of SerialNumber is defined as a Number Datatype. A Text Datatype Field would require different syntax.



The Missinglinq

Richmond, Virginia

The Devil's in the Details!
 
Thank you I did try it and I still got a null value.

Code:
Dim Hospital1 As String


Hospital1 = DLookup("[txtHospitalName]", "TblAQM1Data", "[SerialNumber]= Forms![frmServiceCalls]![txtSerialNumber]")


[\Code]
 
Missinglinq has the main issue. You also have "!." which is wrong. Try either
Code:
variable = DLookup("txtHospitalName", "TblAQM1Data", "[SerialNumber]=" & Forms![frmServiceCalls]![txtSerialNumber])
or if SerialNumber is text
Code:
variable = DLookup("txtHospitalName", "TblAQM1Data", "[SerialNumber]=""" & Forms![frmServiceCalls]![txtSerialNumber] & """")


Duane
Hook'D on Access
MS Access MVP
 
That was a good catch, Duane! I'm looking at a laptop from about 8 feet away and missed the dot-after-the-bang!

I meant to add, for the OPs benefit, that the

Forms![frmServiceCalls]![txtSerialNumber]

could be be replaced with

Me.txtSerialNumber

and the kind of mistakes frequently encountered when using full referencing could be avoided.

The Missinglinq

Richmond, Virginia

The Devil's in the Details!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top