473,666 Members | 2,575 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VBA Dlookup - Using Dlookup in my Private Sub Item___AfterUpd ate()

1 New Member
I'm trying to do a dlookup and I keep getting an error.
I have a table (Supplier_List) with the "Supplier_I D" 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_I D" but not the "Supplier_Name" . I'm trying to populate the form with the "Supplier_Name" . The control "Supplier_N ame" 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 1762
zmbd
5,501 Recognized Expert Moderator Expert
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
4316
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 Klms Distance Jones Melbourne 500 Harrison Sydney 200 Ford Brisbane 700 Jones ...
2
2865
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 error Dim QuoteNumber As String QuoteNumber = Me.txtQuoteNumber Me.txtDealerNumber = DLookup("Dealer_Number", "Quote Table", "Quote_Number=" & txtQuoteNumber)
2
2605
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 much simpler way to do this but here is what I have: Private Sub Combo_Model_Exit(Cancel As Integer) Dim varPrice As Variant varPrice = DLookup("PurchasePrice", "tblModelInfo", "ModelNumber = ") If (Not IsNull(varPrice)) Then Me! =...
8
6283
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 of the X509 token it requires (or so it says). I have followed the instructions in the error message and given the userid full access to the certificate. I have also tried running .NET under my administrators userid which was used to create the...
2
1782
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 Not IsNull(DLookup("", "tbSoortVerzoek", " = """ & Forms!!Soort_verzoek & """")) Then strForm = DLookup("", "tbSoortVerzoek", " = """ & Forms!!Soort_verzoek & """") Else MsgBox ("There is no form available")
3
2473
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("", "tbChargeRate", " >= #" & formateddate & "#") The problem i have is that there maybe several records in tbChargeRate that have PKDateField > Me.SelectedDate. But i only want the first one it comes across, which is what i thought DLookup did.It does...
2
3549
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 user can be found in the table? If the user is not found in the table then open form B DoCmd.Minimize Text19 = DLookup("", "Service", " = text17") Then DoCmd.OpenForm "Assign ", acNormal, , , , , Me.Number Else
19
2615
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 PDF and name each PDF the expression and save into selected folder strMonth. tblBand Members Field Type Rank Text FName Text LName Text MI...
2
1544
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 when I run it from the main form then it gives me run-time error 3075 pointing to 'oleku_id= ' saying that it is missing an operator. I already tried referencing the Me.oleku_id differently: "Forms!main_form!Subform.form!oleku_id". Didn't work either.
0
8454
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8878
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8785
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8560
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 most users, this new feature is actually very convenient. If you want to control the update process,...
1
6200
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5671
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4200
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2776
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
2
1778
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.