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

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 2029
Shannan Casteel via AccessMonster.com 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(strQuery)

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

' Get the data
Set rs = qd.OpenRecordset()

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_AfterUpdate()

If Not IsNull(Me!txtPartNo) And Not Is Null(Me!txtQuantity) 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:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

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

iQA/AwUBQtQbsIechKqOuFEgEQIvDQCeLJvvU9raXOO5eoYLOdsjjn e7FaIAoM+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(strQuery)

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

' Get the data
Set rs = qd.OpenRecordset()

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_AfterUpdate()

If Not IsNull(Me!txtPartNo) And Not Is Null(Me!txtQuantity) 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.com
http://www.accessmonster.com/Uwe/For...ccess/200507/1
Nov 13 '05 #3
Shannan Casteel via AccessMonster.com 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:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

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

iQA/AwUBQtQrUoechKqOuFEgEQLMLgCggQhF0bT1eUuY9Rq5lFd1kM cLAnkAoP40
Mn9X7MSdYSgP+hRmVIAWfvaT
=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.com
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
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...
3
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. ...
1
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,...
1
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...
22
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....
0
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...
3
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...
4
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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
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
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...

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.