473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

DLookup Question

Breezwell
This is probably a simple question for someone out there.

I understand that the DLookup function takes has the following syntax:

DLookup(expression,domain,[criteria])

From what I have read, domain can be a table or query.

I have no problem getting the function to work when I use the actual name of a table for the domain. My question is, can I utilize a combobox that lists the names of my tables and pass the value of the selected table from the combo box to the DLookup function as the domain?

For example, I have a Form named Form1 with a combobox named cmbTables that lists the following table names:

Table1
Table2
Table3

In the DLookup function, is it possible to do something like this:

DLookup("[Names]","[Forms]![Form1].cmbTables","[LastName] = 'Jones'")

I was hoping this, or some sort of similar code, would translate to this:

DLookup("[Names]","Table1","'LastName] = 'Jones'")

Thanks for any and all help.
Oct 10 '08 #1
7 1740
I guess it could work in theory.

Why don't you try it out and see what happens?
Oct 10 '08 #2
DonRayner
489 Expert 256MB
This is probably a simple question for someone out there.

I understand that the DLookup function takes has the following syntax:

DLookup(expression,domain,[criteria])

From what I have read, domain can be a table or query.

I have no problem getting the function to work when I use the actual name of a table for the domain. My question is, can I utilize a combobox that lists the names of my tables and pass the value of the selected table from the combo box to the DLookup function as the domain?

For example, I have a Form named Form1 with a combobox named cmbTables that lists the following table names:

Table1
Table2
Table3

In the DLookup function, is it possible to do something like this:

DLookup("[Names]","[Forms]![Form1].cmbTables","[LastName] = 'Jones'")

I was hoping this, or some sort of similar code, would translate to this:

DLookup("[Names]","Table1","'LastName] = 'Jones'")

Thanks for any and all help.
The way you have it written you are passing the string "[Forms]![Form1].cmbTables" to the dlookup function, I don't think it will work like that. Probally just need to remove the quotes or if that doesnt work maybe something like '"' & [Forms]![Form1].cmbTables & '"'
Oct 10 '08 #3
NeoPa
32,556 Expert Mod 16PB
Don's first guess is right ;)

If the value of the [cmbTables] control is "Table1", then simply leaving the quotes off should do what you require.

Welcome to Bytes!
Oct 12 '08 #4
Thanks everyone for the suggestions.

Sorry for not getting back to this sooner. Been trying to make this work.

I tried removing the quotes, changing the way the quotes were used, etc. but nothing seemed to work. I had to change my entire approach to the initial way I was trying to construct my UI.

Yes, it did seem as though just not having the quotes would work, as I have managed to concatenate form references before in a similar manner outside the DLookup function, so I am still stumped on this one. I may explore this more when I have time, as it would provide a nice way to allow users to specify which tables they want to search from a user-control perspective.

Thanks again for the help.
Oct 12 '08 #5
NeoPa
32,556 Expert Mod 16PB
I'm confident the command works as expected. I can only assume other issues are not as expected. Try adding the following line to see if it shows anything up :
Expand|Select|Wrap|Line Numbers
  1. Call MsgBox("[Names]", _
  2.             [Forms]![Form1].cmbTables, _
  3.             "[LastName] = 'Jones'")
  4. DLookup("[Names]", _
  5.         [Forms]![Form1].cmbTables, _
  6.         "[LastName] = 'Jones'")
Oct 13 '08 #6
NeoPa,

Your confidence was well proven.

I went ahead and put together a small database with minimal data and tried using the table reference without quotes as in the folloiwng:
Expand|Select|Wrap|Line Numbers
  1. Dim var As String
  2. var = DLookup("[Names]", [Forms]![Form1].cmbNames, "[LastName] = 'Jones'")
  3. MsgBox(var)
There were two entries for Jones in the table that the comboox cmbNames listed. Sure enough, the MsgBox displayed the name Jones as predicted and desired. DCount also worked and returned the proper number of Jones entries.

In my original project code, the error was showing up on the DLookup function, so I am not sure what exactly was causing the code to throw the error. I have reworked all that code, so debugging is not something I plan on doing right now. Probably a good lesson for the future.....

Anyway, thanks again for following up on this as I now have another tool to add to my fledgling collection of Access skills.
Oct 13 '08 #7
NeoPa
32,556 Expert Mod 16PB
That's enterprising :)

For assistance with debugging, should you need it in the future, check out Debugging in VBA.
Oct 14 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: sherah | last post by:
I am trying to create a procedure that has values are entered into a table that based on the value entered will programatically decide weather or not the Yes/No should be checked. I am trying to...
1
by: John Hargrove | last post by:
I am building a database to manage test samples in an environmental laboratory. I am learning Access as I go and don't know much about the programming aspects. I hope to make the application...
2
by: Ronny Sigo | last post by:
Hello all, I already put the same question, only now I have more to tell ... Although I used this code before in the same routine (only the fieldname of the table differs) ___ at this point in the...
2
by: ctyrrell | last post by:
I have read with interest the many discussions of the 3048 Error: Cannot open any more databases. I understand how the number of open Table ID's causes the problem. My question has to do with the...
4
by: Karen Bielska | last post by:
I have a table "Customer" with two fields "CusID" (autonumber, PK) and "CusName" (text). If I know the customer's ID, say 215, how can I find the name using DLookup? PS: I'm not really looking...
6
by: Ron | last post by:
Hi All, Was just wondering which is faster, a subreport or dlookup. I've got a report with either 5 subreports or lots of dlookups. The subreports generally have anywhere from 5 to 12...
3
by: OlyOil | last post by:
I have two tables one with a bill of materials and one with the inventory quantities. The bill of materials table contains part numbers that would be found in the inventory table, and I am trying...
9
by: | last post by:
In my database I have a 'control table' in which basic info is stored about the application, for instance the application's path and the name of the company that is using it. In all of the...
15
by: rleepac | last post by:
This is a little complicated but I'll do my best to explain. In my db I have a table called L_AgeCorrection which has the following fields: Age, Sex, Frequency, AgeValue This is a table used to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.