473,396 Members | 1,840 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,396 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 1738
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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...

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.