473,769 Members | 5,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pulling info from linked table based on text box entry

I would like to be able to use 4 text boxes (i.e. Part #, Description,
Quantity, Price) for up to 40 parts. However, only the Part # and Quantity
will be entered. The Description and Price will be pulled from a linked
table. The Price field should take the price for the particular Part # and
multiply it by the quantity and return the value.

The linked table is set up with several columns including Part #, Description,
and Price.

I thought about using a combo box, but there are 57,000+ parts.

Please Help!

Shannan Casteel
--
Message posted via http://www.accessmonster.com
Nov 13 '05 #1
4 2052
Shannan Casteel via AccessMonster.c om wrote:
I would like to be able to use 4 text boxes (i.e. Part #, Description,
Quantity, Price) for up to 40 parts. However, only the Part # and Quantity
will be entered. The Description and Price will be pulled from a linked
table. The Price field should take the price for the particular Part # and
multiply it by the quantity and return the value.

The linked table is set up with several columns including Part #, Description,
and Price.

I thought about using a combo box, but there are 57,000+ parts.


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You can use DLookup() or create a function that runs a query to get the
info you want. I prefer the query 'cuz it is faster than DLookup() when
the table you are searching is > 1000 rows. Here is a function I use to
run queries that return 1 value in 1 row (what you need):

Function getQueryResult( strQuery As String, ParamArray varParams() As
Variant) As Variant
' Purpose:
' Run the indicated query and return the result:
' 1 value in 1 column.
' In:
' strQuery The indicated query
' varParams() The array of parameters.
' 2 elements make up 1 parameter object.
' Format: Parameter name, Parameter value
' Out:
' Variant The result of the query - NULL if no result.
' Errors Return the error to the calling routine.
' Created:
' mgf 25feb2003
' Modified:
'

Dim db As DAO.Database
Dim qd As DAO.QueryDef
Dim rs As DAO.Recordset
Dim i As Integer

Set db = CurrentDb

' Set up the query
Set qd = db.QueryDefs(st rQuery)

For i = LBound(varParam s) To UBound(varParam s) Step 2
qd.Parameters(v arParams(i)) = varParams(i + 1)
Next i

' Get the data
Set rs = qd.OpenRecordse t()

If Not rs.EOF Then getQueryResult = rs(0)

On Error Resume Next
rs.Close
qd.Close
db.Close

End Function

What you'd do is create a query - something like this:

PARAMETER [this_part_no] Long;
SELECT Price
FROM PartPrices
WHERE Part_no = [this_part_no]

Save it as "PartPrice. " Then in VBA code run the above function like
the following in the AfterUpdate event of the txtQuantity TextBox:

Make sure the column Part_no is indexed - so the query runs fastest.

Private Sub txtQuantity_Aft erUpdate()

If Not IsNull(Me!txtPa rtNo) And Not Is Null(Me!txtQuan tity) Then
Me!txtPrice = getQueryResult( "PartPrice" , _
"this_part_ no", _
Me!txtPartNo) * Me!txtQuantity
End If

End Sub

Add your own error traps and/or messages for wrong part number or
missing data elements.

--
MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQtQbsIechKq OuFEgEQIvDQCeLJ vvU9raXOO5eoYLO dsjjne7FaIAoM+p
ujuNKiRfeK7R0N/6RQgKsMKj
=MiLc
-----END PGP SIGNATURE-----
Nov 13 '05 #2
MGFoster,

Thanks for your help in this. I made a query with PartNumber,
PartDescription , and Price. Now, do I enter the
PARAMETER [this_part_no] Long;
SELECT Price
FROM PartPrices
WHERE Part_no = [this_part_no]


part under the criteria for PartNumber in the query? I tried doing that and
it kept giving me a slew of errors like incorrect syntax. So I haven't been
able to test your method yet.

Thanks for your help.

Shannan

MGFoster wrote:
I would like to be able to use 4 text boxes (i.e. Part #, Description,
Quantity, Price) for up to 40 parts. However, only the Part # and Quantity

[quoted text clipped - 6 lines]

I thought about using a combo box, but there are 57,000+ parts.


You can use DLookup() or create a function that runs a query to get the
info you want. I prefer the query 'cuz it is faster than DLookup() when
the table you are searching is > 1000 rows. Here is a function I use to
run queries that return 1 value in 1 row (what you need):

Function getQueryResult( strQuery As String, ParamArray varParams() As
Variant) As Variant
' Purpose:
' Run the indicated query and return the result:
' 1 value in 1 column.
' In:
' strQuery The indicated query
' varParams() The array of parameters.
' 2 elements make up 1 parameter object.
' Format: Parameter name, Parameter value
' Out:
' Variant The result of the query - NULL if no result.
' Errors Return the error to the calling routine.
' Created:
' mgf 25feb2003
' Modified:
'

Dim db As DAO.Database
Dim qd As DAO.QueryDef
Dim rs As DAO.Recordset
Dim i As Integer

Set db = CurrentDb

' Set up the query
Set qd = db.QueryDefs(st rQuery)

For i = LBound(varParam s) To UBound(varParam s) Step 2
qd.Parameters(v arParams(i)) = varParams(i + 1)
Next i

' Get the data
Set rs = qd.OpenRecordse t()

If Not rs.EOF Then getQueryResult = rs(0)

On Error Resume Next
rs.Close
qd.Close
db.Close

End Function

What you'd do is create a query - something like this:

PARAMETER [this_part_no] Long;
SELECT Price
FROM PartPrices
WHERE Part_no = [this_part_no]

Save it as "PartPrice. " Then in VBA code run the above function like
the following in the AfterUpdate event of the txtQuantity TextBox:

Make sure the column Part_no is indexed - so the query runs fastest.

Private Sub txtQuantity_Aft erUpdate()

If Not IsNull(Me!txtPa rtNo) And Not Is Null(Me!txtQuan tity) Then
Me!txtPrice = getQueryResult( "PartPrice" , _
"this_part_ no", _
Me!txtPartNo) * Me!txtQuantity
End If

End Sub

Add your own error traps and/or messages for wrong part number or
missing data elements.

--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200507/1
Nov 13 '05 #3
Shannan Casteel via AccessMonster.c om wrote:
MGFoster,

Thanks for your help in this. I made a query with PartNumber,
PartDescription , and Price. Now, do I enter the

PARAMETER [this_part_no] Long;
SELECT Price

FROM PartPrices

WHERE Part_no = [this_part_no]

part under the criteria for PartNumber in the query? I tried doing that and
it kept giving me a slew of errors like incorrect syntax. So I haven't been
able to test your method yet.


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

What I gave you is only an example SQL SELECT command that returns the
price of the indicated part number ([this_part_no] - the criteria). It
is meant to go in the SQL View of a query. It would only work if you
had a table named PartPrices & it was set up with the columns I
indicated in the SELECT command. It was not meant to be used "straight
out of the box." It is only an example. Learn SQL, it will help you a
lot.

In a QBE grid you drag the price column and the part number column onto
the grid. Uncheck the part number's "Show" check box. In the part
number's criteria cell put [this_part_no].

Run the query to see if it works - be sure to use a valid part number in
the parameter prompt (that will appear when you run the query). It
should return only one price for the part number (unless you have a
different PartPrices table set up).

--
MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQtQrUoechKq OuFEgEQLMLgCggQ hF0bT1eUuY9Rq5l Fd1kMcLAnkAoP40
Mn9X7MSdYSgP+hR mVIAWfvaT
=MzH1
-----END PGP SIGNATURE-----
Nov 13 '05 #4
MGFoster,

The SQL code wouldn't work. It won't let me save the query. An error
message appears saying there should be an expected INSERT, DELETE, etc....

MGFoster wrote:
MGFoster,

[quoted text clipped - 11 lines]
it kept giving me a slew of errors like incorrect syntax. So I haven't been
able to test your method yet.


What I gave you is only an example SQL SELECT command that returns the
price of the indicated part number ([this_part_no] - the criteria). It
is meant to go in the SQL View of a query. It would only work if you
had a table named PartPrices & it was set up with the columns I
indicated in the SELECT command. It was not meant to be used "straight
out of the box." It is only an example. Learn SQL, it will help you a
lot.

In a QBE grid you drag the price column and the part number column onto
the grid. Uncheck the part number's "Show" check box. In the part
number's criteria cell put [this_part_no].

Run the query to see if it works - be sure to use a valid part number in
the parameter prompt (that will appear when you run the query). It
should return only one price for the part number (unless you have a
different PartPrices table set up).

--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200507/1
Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
4490
by: Bernie | last post by:
Greetings, I have 3 servers all running SQL Server 2000 - 8.00.818. Lets call them parent, child1, and child 2. On parent, I create a view called item as follows: CREATE view Item as select * from child1.dbchild1.dbo.Item union all select * from child2.DBChild2.dbo.Item
3
19495
by: Michael Plant | last post by:
Hello one and all. I have a stored table in my database and the form I'm using is based on a query that draws data from my stored table and a linked table. The linked table is a *.txt file. However, whenever I try to edit data I get the error message "Updating data in a linked table is not supported by this ISAM." I can understand not being able to edit the linked data, but the field I'm trying to update is drawn from the stored...
1
293
by: Randy Lucero | last post by:
I have a question for all you experts out there. I have created an Order Entry form that displays a Customer Name from a table called "CustList". That table also contains the usual.. address, city, etc. to include a CustID field. On the Order Entry form, I choose the Customer Name and I am displaying CustID by means of "=txtCustomer.Column(1)" which corosponds with the Customer Name.
1
1572
by: Mr. B | last post by:
VB.net 2003 c/w Framework 1.1 and MS Access db We have a commercial program that does our Acounting and Time Sheets (Timberline). At least once a day our Accounting department runs a Script file that Exports info into an MS Access db file and which has 7 Tables (stuff like Project info, Project numbers, User names, etc). I wrote a Time Sheet entry application to read this info and to allow Employees to write their Time Sheet data into...
22
18812
by: RayPower | last post by:
I'm having problem with using DAO recordset to append record into a table and subsequent code to update other tables in a transaction. The MDB is Access 2000 with the latest service pack of JET 4. The system is client/server, multiusers based. The MDBs are using record locking. Here is part of the code: Dim wkSpace As Workspace, db As Database Dim rstTrans As DAO.Recordset Set wkSpace = DBEngine.Workspaces(0)
0
1554
by: HydroPnik | last post by:
Hi all! What a great community you have here. Being an Access newbie I have already used much information gleaned from the other posters for my current project. I have been tasked with creating a database that will link to a table ("tbl_Data File) located in another database ("Database1"). Changes will be made to a customer record queried from Database1 and saved in a table located in Database2 called "tbl_Instructions". So far I have...
3
4011
by: acecraig100 | last post by:
I am fairly new to Javascript. I have a form that users fill out to enter an animal to exhibit at a fair. Because we have no way of knowing, how many animals a user may enter, I created a table with a createElement function to add additional entries. The table has the first row of input text boxes already in it. You have to click a button to add another row. That seems to be working fine. How do I pull the information from the input boxes...
4
3309
theaybaras
by: theaybaras | last post by:
Hi everyone, You've all been such a huge help to me since joining, and I'd just like to take a second to let you know how much I appreciate it! That said, I have another supplication! ;) I have a db of scientific article citations and data extracted from the papers. When I first made this db I knew nothing of normalization, and that has been a MAJOR pain, as you can well imagine. I have worked to get this normalized and I have just one...
1
1435
by: TaylorLeonard | last post by:
Hi, I have been trying to figure this out for hours, but can't seem to get it. I have a form where the administrator inputs someone elses personal info (FirstName, lastName, email, phone#, etc.) and when they click enter, I have it so a new entry is created in my Volunteer table. What i would like to do it, is when the admin clicks the enter button, a new entry will be made in the Password table. When a new record is added to the Volunteer...
0
9586
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
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10210
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
8869
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
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
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3956
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
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
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.