UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Dlookup With Criteria's Column Name Coming From A Text-box And Value From Another Text-box., Access 2010    
 
   
NewToAccess2019
post Aug 26 2019, 10:57 AM
Post#1



Posts: 28
Joined: 21-March 19



Hi All,

I have used Dlookup a few times, great function. The usual syntax I follow is:

Dlookup("[FieldAFromTable]","tableName","criteria") ex- Dlookup("ID","tblEmployee","RoleID= '" & Me!txtEnterRollID & "'")

or

Dim TableNamez as String
TableNamez = Cstr(Me.txtBoxTableName.value)
JobID= Dlookup("ID",TableNamez,"RoleID= '" & Me!txtFieldValue & "'")

So, I am getting the tablename in a textbox and passing it in a string variable and using it without quotes "" in the dlookup function).

Now my query is:


I want to fetch the value of the column name from a textbox and pass it in a variable, after that I want to use that variable in the dlookup function.
The reason is (I am using a utility which searches for any text across different tables and the result is shows tablename and column name in two different textboxes.

I dont know the syntax to pass a variable instead of a fixed columnName.


Dim TableNamez as String
Dim ColumnNamez as String
TableNamez = Cstr(Me.txtBoxTableName.value)
ColumnNamez = Cstr(Me.txtBoxFieldName.value)
JobID= Dlookup("ID",TableNamez, ColumnNamez= " & Me!txtFieldValue & ")

txtFieldValue stores the value in that field.
This post has been edited by NewToAccess2019: Aug 26 2019, 10:58 AM
Go to the top of the page
 
theDBguy
post Aug 26 2019, 11:09 AM
Post#2


Access Wiki and Forums Moderator
Posts: 76,425
Joined: 19-June 07
From: SunnySandyEggo


Hi. Welcome to UA! welcome2UA.gif

You could try something like:
CODE
DLookup("ID",TableNamez,ColumnNamez & "=" & Me.txtFieldValue)
Hope it helps...

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
NewToAccess2019
post Aug 26 2019, 11:19 AM
Post#3



Posts: 28
Joined: 21-March 19



@thedbGuy

Thanks for the quick reply and the welcome smile.gif

I tried it, I can see that its taking the column name, but I am still getting an error.

Error screenshot attached.

I tried this as well and few other combinations, but it didnt work:

Me.Origin.Value = DLookup("[JOB]", tableNamez, "FieldNamez & " = " & Me.mem_Value")
This post has been edited by NewToAccess2019: Aug 26 2019, 11:19 AM
Attached File(s)
Attached File  error.png ( 14.48K )Number of downloads: 6
 
Go to the top of the page
 
theDBguy
post Aug 26 2019, 11:23 AM
Post#4


Access Wiki and Forums Moderator
Posts: 76,425
Joined: 19-June 07
From: SunnySandyEggo


Hi. Since the field appears to be a text field, you could try it this way:
CODE
DLookup("ID",TableNamez,ColumnNamez & "='" & Me.txtFieldValue & "'")

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
NewToAccess2019
post Aug 26 2019, 11:26 AM
Post#5



Posts: 28
Joined: 21-March 19



worked like a charm.
Thank you so much!
Go to the top of the page
 
theDBguy
post Aug 26 2019, 11:32 AM
Post#6


Access Wiki and Forums Moderator
Posts: 76,425
Joined: 19-June 07
From: SunnySandyEggo


Hi. You're welcome. Glad we could assist. Good luck with your project.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    23rd October 2019 - 04:26 PM