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

How to automatically fill-in a field based off of a previous field in Access 2007

1
Database Details:
I have 2 tables; "tblContracts" and "tblVendorInfo" and a form ("frmVendorInfo) created off of the table "tblVendorInfo". I have fields including: "PO Number" (Primary Key), "Vendor", "Street", and "Zip" in the table "tblContracts". All the PO Numbers, Vendors, etc. are stored in the table "tblContracts".

My Question:
I need to know how to automatically fill-in the "Vendor", "Street", and "Zip" fields once a "PO Number" is selected from a combo box on the form. Does this have to be done by a dlookup? Or can it be easier than that?

What I've been trying:
I have attempted to research this and I came up with some code such as:

Expand|Select|Wrap|Line Numbers
  1. Private Sub PONumber_AfterUpdate()
  2.  
  3.     Vendor = DLookup("Vendor", "tblContracts", "PO Number =" & PONumber)
  4.  
  5. End Sub
I'm getting Run-time error '3075'
Syntax error (missing operator) in
Query expression 'PO Number=WWV11858'

I am a beginner and any very simplified help would be much appreciated. Let me know if I'm on the right track or I should be doing something totally different. Thanks!!

Jon
Mar 22 '11 #1
2 3848
VijaySofist
107 100+
Hi John,

Please Dont use Spaces while creating Fields. Any way Try Giving Field names in between Square Brackets.
Please Try the Following Code

Expand|Select|Wrap|Line Numbers
  1. Private Sub PONumber_AfterUpdate()
  2. Vendor = DLookup("[Vendor]", "tblContracts", "[PO Number] =" & PONumber)
  3. End Sub
  4.  
You Can Find the Syntax & Example in below

Syntax
DLookup(expr, domain [, criteria] )

Argument Description
expr Required. An expression that identifies the field whose value you want to return. It can be a string expression (string expression: An expression that evaluates to a sequence of contiguous characters. Elements of the expression can be: functions that return a string or a string Variant (VarType 8); a string literal, constant, variable, or Variant.) identifying a field in a table or query, or it can be an expression that performs a calculation on data in that field. In expr, you can include the name of a field in a table, a control on a form, a constant, or a function. If expr includes a function, it can be either built-in or user-defined, but not another domain aggregate or SQL aggregate function.
domain Required. A string expression identifying the set of records that constitutes the domain. It can be a table name or a query name for a query that does not require a parameter.
criteria Optional. A string expression used to restrict the range of data on which the DLookup function is performed. For example, criteria is often equivalent to the WHERE clause in an SQL expression, without the word WHERE. If criteria is omitted, the DLookup function evaluates expr against the entire domain. Any field that is included in criteria must also be a field in domain; otherwise, the DLookup function returns a Null (Null: A value you can enter in a field or use in expressions or queries to indicate missing or unknown data. In Visual Basic, the Null keyword indicates a Null value. Some fields, such as primary key fields, can't contain a Null value.).

Example

Expand|Select|Wrap|Line Numbers
  1. Dim intSearch As Integer
  2. Dim varX As Variant
  3.  
  4. intSearch = 1
  5. varX = DLookup("[CompanyName]", "Shippers", _
  6.     "[ShipperID] = " & intSearch)
  7.  
All the Best
Regards
Vijay.R
Apr 1 '11 #2
NeoPa
32,556 Expert Mod 16PB
Jon, your syntax is wrong because, although you didn't mention it in the question, it seems that [PO Number] is a text field. For text literals you need quotes (See Quotes (') and Double-Quotes (") - Where and When to use them). Your code would need to look more like :
Expand|Select|Wrap|Line Numbers
  1. Vendor = DLookup("[Vendor]", _
  2.                  "[tblContracts]", _
  3.                  "[PO Number] ='" & Me.PONumber & "'")
All that being said, I suspect you're going about this the wrong way anyway. Check out Cascading Combo/List Boxes for a more straightforward approach.
Apr 3 '11 #3

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

Similar topics

3
by: paul b | last post by:
Hello, I have a small problem in PHP an perhaps someone can help me: I have a simple HTML login page with a username and a password field, as well as a submit button, which I have to use for...
1
by: Nick D. | last post by:
Hi All! I hope there's someone that might be able to help me with this...I'm a designer, not a developer, so i hope this isn't TOO basic. Basically, I have a topbar that's a simple JPG image that...
0
by: Tom | last post by:
Hi, Here is my C# code for a simple web logon form: After I added the sqlDataAdapter1, sqlConnection1, dataSet1 and compile the program, there was build error which said it did not find...
1
by: rapataa | last post by:
Hi, I'm trying to write a generic base class to loop through data and fill my collection objects. The thing is that the base class doesn't know the type of the object I guess. The code should...
5
by: Q. John Chen | last post by:
I redirect my user to the UPS tracking page. That's simple. What I want to do are: 1. I have my user's tracking number and I want to automatically enter the tracking number for the user. (At...
4
by: jaYPee | last post by:
I have already done some code to fill the datagrid. my problem is that the fill method is too slow after executing my code. here is the scenario. i have a parent/child form. all is datagrid....
0
by: Sam | last post by:
Hi, I'm trying to fill a dataset using two requests : select column_name as column_name1, data_type as data_type1 from information_schema.columns where table_name = 'table1' and select...
1
by: John Bailo | last post by:
using ( SqlCommand cmd = new SqlCommand("select * sample"), new SqlConnection( sqlDsn ) ) ) { SqlDataAdapter adapter = new SqlDataAdapter(cmd); DataTable dt = new DataTable();...
1
by: Chris Smith | last post by:
Does anyone know of any python scripts that can help me automatically navigate through some forms so I can schedule the download the file at the end of all the questions?
4
by: Terry | last post by:
I am trying to figure out if there is a way to get a regular asp.net TextBox to fill the screen, both height and width. When I drop a TextBox onto a blank asp.net page and set the height="100%",...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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
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,...
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...

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.