473,406 Members | 2,378 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,406 software developers and data experts.

Lookup records in existing query and display on a form

Hey,
I am currently working on a form which requires user to enter customer ID and then display corresponding records with that customer ID, ex. customer status, amount spent etc. I did some research and realized there's a function called "DLookup" can do the work for me but just confused how to use it correctly.

I setted up an update button. After entering customer ID in a seperate text box and press the update button, the corresponding records would show up in other text boxes. And the code I used is in the following (an example for one text box):

Expand|Select|Wrap|Line Numbers
  1.  Private Sub CmdUpdate_Click()
  2.        Me.lblCustomerStat.Caption = DLookup("Customer Status", "Query.[Asset Status Query]", "Query.[Asset Status Query].ID = Me.txtCustomerID")
  3.  
  4. End Sub
  5.  
which did not work.... could someone help me please
Jan 9 '12 #1

✓ answered by NeoPa

Try this slightly changed one instead :
Expand|Select|Wrap|Line Numbers
  1. Me.lblCustomerStat.Caption = DLookup(Expr:="[Customer Status]", _
  2.                                      Domain:="[Asset Status Query]", _
  3.                                      Criteria:="[ID] =" & Me.txtCustomerID)
Named parameters aren't necessary, but they're clearer when the line is so long it should be split (I split after eighty characters but any reasonable number that allows the code to be read without horizontal scrolling is fine).

5 1713
Seth Schrock
2,965 Expert 2GB
The reason your code doesn't work is that you have your syntax wrong. The correct command would be

Expand|Select|Wrap|Line Numbers
  1. Me.lblCustomerStat.Caption = DLookup("Customer Status", "Asset Status Query", "ID =" & txtCustomerID)
Chances are however there is a better way of doing things. DLookup() is slow and the information can be gained through a query. Also, a query can return multiple records while DLookup can only return one. You mentioned that you were wanting to display corresponding records (plural) so I thought you might want to know that part. I'm not exactly sure what you are trying to do, but I'm going to hazard a guess and say that it would be better to create a query that has all the fields you need and then set the criteria to be the Customer ID in the textbox of on the form. You could then make the form do a requery every time you updated the Customer ID. Just base a subform on the query that you create and have the subform go below the Customer ID textbox.
Jan 9 '12 #2
Hey Seth,
Really appreciate for your reply! and I have tried the Dlookup code you provided. It showed a syntax error saying "missing operator in query expression 'Customer Status'". I have checked back and forth but have no idea why it happened...isn't it just the field name of the record that I am looking for?
Also, u mentioned create subform to requery every time you update the customer ID. What I am trying to do here is enter the customer ID and have several fields in the bottom like Customer Status, Customer Address etc and have them show the corresponding records of the very ID I input earier. Usually there would be just one record in each field. Is this still applies to what you suggested about building a subform? If it is how would you do it step by step?
Really appreaciate your help again!!
Jan 10 '12 #3
NeoPa
32,556 Expert Mod 16PB
Try this slightly changed one instead :
Expand|Select|Wrap|Line Numbers
  1. Me.lblCustomerStat.Caption = DLookup(Expr:="[Customer Status]", _
  2.                                      Domain:="[Asset Status Query]", _
  3.                                      Criteria:="[ID] =" & Me.txtCustomerID)
Named parameters aren't necessary, but they're clearer when the line is so long it should be split (I split after eighty characters but any reasonable number that allows the code to be read without horizontal scrolling is fine).
Jan 11 '12 #4
Thank you NeoPa!! it is working now~~
Jan 11 '12 #5
NeoPa
32,556 Expert Mod 16PB
Pleased to hear it Annabelle :-)

Names with embedded spaces usually need the brackets [] to indicate where the end of the name is. Otherwise it treats the space as the end.
Jan 11 '12 #6

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

Similar topics

2
by: William Wisnieski | last post by:
Hello Everyone Access 2000 Looking for some suggestions and advice on how to proceed with this. I hope its not as complicated as it seems to me right now. I've got an unbound main form...
9
by: Sandy | last post by:
Hi all, I have a form to list records (frmListIssue) which I call from different other forms. My wish is to display a message when the form is called and empty; no records to display. I want to...
12
by: Tom | last post by:
Hello, I have a database of employee data in access and I am trying to create a form with combo boxes for criteria (ex. gender, office, position, etc.) that let the user select criteria from...
6
by: ljungers | last post by:
Hi to all and hope someone may have an answer for me. I have a Form named Cust_lukup_Form that has 3 text boxes and a click button that uses a OnClick to call Cust_lukup_Macro that runs an...
2
by: Certys | last post by:
Hello, I have a form where I only allow new records to be added. I enable this by setting the form property "Data Entry" to Yes. I want to access other records in the same table- to autofill...
1
by: ReubenPatterson | last post by:
Hi All, I'm struggling to get a QBF query working. I have 9 fields and a date range in the form. When I put these fields into the Design View and use the criteria (except the date range which uses...
1
by: Arnold | last post by:
Greetings, I have a form, frmProgressReports, with qryProgressReports as the recordsource. A field in the query is named 'Select" and is yes/no, with criteria set to true. This filters the form...
2
by: vinceboy | last post by:
Hi anybody. I am newbie here and would like to know that how can I validate both drop down menu and radio button from a dynamic display form.Something went wrong with my script.The radio button is...
5
by: Ferasse | last post by:
Hi, I'm an occasional Ms-Access developer, so there is still a lot of stuff that I don't get... Right now, I'm working on a database that stores contractual information. One of the form that...
5
by: erog | last post by:
Hello I've tried using the MS Access Northwind sample DB and I've downloaded a few other sample Microsoft Access DBs from their website. I keep on running into the same problem for trying to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.