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

VBA Dlookup - Using Dlookup in my Private Sub Item___AfterUpdate()

1
I'm trying to do a dlookup and I keep getting an error.
I have a table (Supplier_List) with the "Supplier_ID" and the "Supplier_Name".
I have another table that I'm using on my form (“Item Table” to get populate it. It has the "Supplier_ID" but not the "Supplier_Name". I'm trying to populate the form with the "Supplier_Name". The control "Supplier_Name" is called "Supplier"
I'm using the following code but nothing is coming up. Help :{

Expand|Select|Wrap|Line Numbers
  1. Private Sub Item___AfterUpdate()
  2. Me.Supplier = DLookup("Supplier", "Supplier List", "[Supplier_ID]='" & Me.Supplier_Id & "'")
  3. End Sub
Apr 26 '15 #1
1 1740
zmbd
5,501 Expert Mod 4TB
You've stumbled upon one of my pet peeves by building the criteria string within the command - and it's not your fault because that's how a majority of examples show how to use the command.
Instead I suggest that you build the string first and then use the string in the command.

Why you might ask, because you can then check how the string is actually resolving; thus, making troubleshooting the code so much easier as most of the time the issue is with something missing or not resolving properly/as expected within your string.

So to use your code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Item___AfterUpdate()
  2.  
  3. DIM strSQL as string
  4. strSQL = "[Supplier_ID]='" & Me.Supplier_Id & "'"
  5. '
  6. 'now you can insert a debug print here for troubleshooting
  7. ' - press <ctrl><g> to open the immediate window
  8. ' - you can now cut and paste this information for review!
  9. '
  10. debug.print "Your criteria = " & strSQL
  11. '
  12. 'now use the string in your code:
  13. Me.Supplier = DLookup("Supplier", "Supplier List", strSQL)
If you will make these little changes and post back the resolved string we can help you tweak the code.

The second thing to look at... Me.Supplier_Id - are you sure that this is a text field?
Apr 26 '15 #2

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

Similar topics

8
by: Christine Henderson | last post by:
I have a problem using the above function in the following simplified circumstance: In the lookup table called "Klms Travelled" I have 3 fields, eg: Receiver Name Receiver Suburb ...
2
by: jonvan20 | last post by:
I have been having trouble with a simple Dlookup command that was Reccommended to me by a nice fellow named Vic, On the other hand I have statements like this that wont run they give me a run time...
2
by: CrazyAL | last post by:
I am working on a form to add entries into my assets table. I am trying to figure out how to make a purchase price field auto populate after entering model number into a combo box. There maybe a...
8
by: =?Utf-8?B?RGFuTQ==?= | last post by:
Can someone help with the following problem. I am sending an encrypted SOAP message to a .NET 2.0 + WSE 3.0 web service. When .NET attempts to decrypt the message it cannot read the private key...
2
by: John | last post by:
To prevent the null-error from showing up when dlookup returns false I created the code beneath which doesn't seem very elegant. How can I code this without having to use the dlookup twice? If...
3
reginaldmerritt
by: reginaldmerritt | last post by:
I'm using Dlookup to search a table for the first record it comes across that has a date >= the date i specifiy. e.g. formateddate = format(Me.SelectedDate,"mmddyy") VarX = DLookup("",...
2
by: toadmaster | last post by:
I am trying to get an onclick event to open a form based on the logged in username from Windows. The idea is to open either form A or B after I have used DLookup to check a table to see if the...
19
Brilstern
by: Brilstern | last post by:
Q: I am getting "invalid use of null" error. Whats wrong?!? The goal in this command is to first create a individual report "rptECR" for each SSN in tblBand Members. Next, save each report as a...
2
by: tujurikkuja | last post by:
Private Sub Form_Load() Text9.value = DLookup("oleku_nimi", "", "oleku_id= " & Me.oleku_id) End Sub This should fill a field on a subform. When I run just the subform then it works fine. But...
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: 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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.