p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Access (http://p2p.wrox.com/forumdisplay.php?f=18)
-   -   Dlookup and variables (http://p2p.wrox.com/showthread.php?t=48306)

Jaqx September 26th, 2006 07:31 AM

Dlookup and variables
I am attemting to pass a variable field name to strFldNm but the dlookup returns the value held in strFldNm instead of the value in the field by that name


varVal = DLookup("['" & strFldNm & "']", "tblUsers", "[userName]='" & Forms!frmMain!Combo10 & "'")

varVal="db_Access" INSTEAD OF "-1"

What have I got wrong?

dartcoach September 26th, 2006 09:07 AM

Does the dlookup work if you use the actual field name vs the variable?



Jaqx September 29th, 2006 03:28 AM

Yes, I can construct a string with the field name proper in place, but the whole point is that I thought that I might to be able to construct the string with the field name itself as a variable. That way one standard DLOOKUP string in this instance could be used on any field of choice without having to construct a string per field.

mmcdonal September 29th, 2006 06:47 AM

Does this matter?

varVal = DLookup("['" & strFldNm & "']", "tblUsers", "[userName]='" & Forms!frmMain!Combo10 & "'")

Should be:
varVal = DLookup("['" & strFldNm & "']", "tblUsers", "[userName]='" & [Forms]![frmMain].[Combo10] & "'")


All times are GMT -4. The time now is 08:43 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.