473,549 Members | 2,408 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DLookup won't return value from Combo Box

13 New Member
Hi,

I have a problem that had me going around in circles for days now.

I have a combo box which updates from another combo box correctly. I'm now trying to get trying to get a text box to display a value based on the selection from the second combo box. My after event code is:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboActivity_AfterUpdate()
  2. Me.cboRateHigh = DLookup("ProductivityRateHigh", "tblUnitPeriod", "ID= ' " & Me.cboActivity & " ' ")
  3. End Sub
ID is the primary key and a number. The value returned in the combo box is text. I think this is where the issue is, because for some reason the Combo box doesn't seem show the PK (number) if I display the other columns.

I'm currently getting a run-time error 3464 'Data type mismatch in criteria expression'.

Thanks in advance for the help.
Jul 17 '19 #1
6 1447
NeoPa
32,564 Recognized Expert Moderator MVP
Put very simply, your quotes tell DLookup() that the value is a string and NOT a number (See Quotes (') and Double-Quotes (") - Where and When to use them).
Jul 17 '19 #2
twinnyfo
3,653 Recognized Expert Moderator Specialist
Not to mention that your quotes are including extra spaces on each side of your Combo Box's value, so, even if it could have been able to find that value taken as a string (which it might), you were looking for the wrong value in the first place.

As NeoPa suggests, your proper syntax should be:

Expand|Select|Wrap|Line Numbers
  1. Me.cboRateHigh = _
  2.     DLookup("ProductivityRateHigh", _
  3.             "tblUnitPeriod", _
  4.             "ID=" & Me.cboActivity)
However, this assumes that the Combo Box's bound column is the Primary Key.
Jul 17 '19 #3
NeoPa
32,564 Recognized Expert Moderator MVP
Thanks Twinny. That makes the concept clearer.
Jul 17 '19 #4
AdmiralN
13 New Member
Thanks very much for your help and also to NeoPa.

I have tried your correction and I'm now getting run-time error 3075
syntax error (missing operator) in query expression 'ID=(the variable)'.

I think the problem now is, as you suggested, the that the combo boxs Primary Key is not the bound column, as I can't see any values if I try to view all columns in the combo box.

The the after event code for the combo box is:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboPackageNumber_AfterUpdate()
  2. Dim strSql As String
  3. strSql = "SELECT o.Activity" & vbCrLf & _
  4. "FROM tblActivity AS o" & vbCrLf & _
  5. "WHERE o.PackageID = '" & cboPackageNumber.Value & "'" & vbCrLf & _
  6. "ORDER BY o.PackageID;"
  7. Debug.Print strSql
  8. cboActivity.RowSource = strSql
  9. End Sub
Thanks again in advance.
Jul 18 '19 #5
twinnyfo
3,653 Recognized Expert Moderator Specialist
Your SQL should be
Expand|Select|Wrap|Line Numbers
  1. SELECT o.PackageID, o.Activity .....
You also need to make sure the combo box is formatted for two columns, with the first column being bound.

Hope this hepps.
Jul 18 '19 #6
AdmiralN
13 New Member
Thanks so much for your help! That's what I couldn't figure out.
Jul 18 '19 #7

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

Similar topics

3
2340
by: tshad | last post by:
I am trying to set up a class to handle my database accesses. I can't seem to figure out how to get the return value from my dataReader from these routines (most of which I got elsewhere). They do work pretty well, except for the change I made to get the return value. For example, I have the following:...
5
1175
by: marcmc | last post by:
Is it in any way possible to have a sProc called and executed within SQLServer return its return value to an open .Net Vb application? As a programmer I beleive this can be done and if I wreck my head enough I will find a way. I have toyed with the ideas of xml, SQLServer events but have found nothing so far. As this is the final stage of...
1
2331
by: annbb | last post by:
I have a piece of code which resets all the control on a form ..but if I also put an option group on the form and the relevant code in the routine to reset it I get an error message saying that you cant assign a value to this object when the code reaches the line for the checkbox. The code works perfectly if EITHER option group or checkbox...
20
3572
by: lovecreatesbeauty | last post by:
Hello experts, Is the following code snippet legal? If it is, how can exit() do the keyword return a favor and give a return value to the main function? Can a function call (or only this exit(n)) statement provide both function call and return features of the C programming language? /* headers omitted */ int main (void)
6
1884
by: Tim Roberts | last post by:
I've been doing COM a long time, but I've just come across a behavior with late binding that surprises me. VB and VBS are not my normal milieux, so I'm hoping someone can point me to a document that describes this. Here's the setup. We have a COM server, written in Python. For completeness, here is the script: ----- testserver.py...
2
2661
by: philip | last post by:
hello, i am new to asp.net and sql server, and i have 3 questions for asking: 1. i am writing a store procedure of login validation for my asp.net application and wondering what the different between RETURN and SELECT is. if exists(select * from users where username = @username and password = @password) BEGIN
173
7974
by: Marty James | last post by:
Howdy, I was reflecting recently on malloc. Obviously, for tiny allocations like 20 bytes to strcpy a filename or something, there's no point putting in a check on the return value of malloc. OTOH, if you're allocating a gigabyte for a large array, this might fail, so you should definitely check for a NULL return.
101
4238
by: Tinkertim | last post by:
Hi, I have often wondered if casting the return value of malloc() (or friends) actually helps anything, recent threads here suggest that it does not .. so I hope to find out. For instance : char *tmp = NULL;
2
1942
by: thierry savard | last post by:
I want the 2 compute column to show only 4 decimal, but I cant find a way to affect the return value of 'em. I wrote down this command "compute avg(x)" because I need the average to be in a seperate table. When you use compute avg(x) here x is cast (price as decimal(10,4)) because I need the price to show up in the main table, and I need it...
11
1511
by: Rheigny | last post by:
I dont know why I cant pass the value of AccountType (from TblAccount) to Me.txtWAccounType(textbox from WithdrawView) pls help me.. here's my code If IsNull(DLookup("", "TblAccount", "AccountId = '" & txtWAccountId & "'")) Then MsgBox "Account Number Doesn't Exist" Else Me.txtWAccounType.Value = DLookup("", "TblAccount", "AccountId...
0
7736
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7982
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7500
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7827
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5385
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5110
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1961
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1079
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
783
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.