473,466 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Create 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

✓ answered by twinnyfo

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.

6 1439
NeoPa
32,556 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,556 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
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...
5
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...
1
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...
20
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...
6
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...
2
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...
173
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....
101
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 : ...
2
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...
11
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",...
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
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
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
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...
1
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.