473,387 Members | 1,463 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.

Access Data from a txtBox on a form using SQL

Hi all,
First let me start out with what I want to happen with this and then
maybe y'all can give me some better insight. I have a database in
Microsoft Access which we need to upsize to SQL. We currently have a
problem with it now. On one of our forms (frmScan, which is an unbound
form with two unbound controls) there is a txtBox contorl (txtScan)
which gets a number from a barcode put into it (usually a 9 character
varchar). I have a list box underneath this control which uses a query
as its rowsource. The trick is, I want that query to filter its data
using the specified information in the txtScan control. In access I
did this eaisly with a module and some VBA. But SQL wont let me work
like this now (or I don't know quite how to work with it now). Any
suggestions?

Thanks,
Marcus

Nov 13 '05 #1
3 1506
You can try the following:

(first, I shall assume that the two tables involved are linked to tables on
sql server, and those tables can be viewed when you simply click on the
table name in the standard "tables" tab. I am also assuming that we are
talking about linked tables (odbc)....however, the following should also
work if you are in fact used a adp proejct.

What I would do is in the txtScan after update event, simply stuff in the
sql source into the listbox.

So, in the after update event, you go:

dim strSql as string

strSql = "select * from tblProducts where ProductCode = " & me.txtScan & _
" Order by ProductDescription"

me.MyListbox.RowSource = strSql

Of course, if your ProducutCode, (or whatever you filter by) is a string,
then we need:

strSql = "select * from tblProducts where ProductCode = '" & me.txtScan &
"'"
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
http://www.attcanada.net/~kallal.msn
Nov 13 '05 #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Is the ListBox's RowSource property an SQL string or the name of a
query/table?

Usually I set up the RowSource to use an SQL string w/ a ref to the
control I want to use as a filter. E.g.:

SELECT * FROM table_name WHERE column_name = Form!control_name

The "Form!control_name" pulls the data from the control on the current
form. I believe this format can be used in an .adp or ODBC linked
table.

Required: In the control's AfterUpdate event .Requery the ListBox.

If you want to use a stored procedure (SP) you can put something like
this in the ListBox's RowSource property:

EXEC usp_SP_Name control_name

"control_name" will act as the parameter to the SP "usp_SP_Name." If
that doesn't work, you may have to use a syntax like this:

"EXEC usp_SP_Name " & Form!control_name

Remember to .Requery the ListBox in the TextBox's AfterUpdate event.

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

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

iQA/AwUBQUIlp4echKqOuFEgEQLKvACgqp5r5+PI9eiQydg9o6qJhM 4gOmMAoJQf
qWYf4qQQ6rCmXx4Pc90/yzCF
=XKOa
-----END PGP SIGNATURE-----
Magno101 wrote:
Hi all,
First let me start out with what I want to happen with this and then
maybe y'all can give me some better insight. I have a database in
Microsoft Access which we need to upsize to SQL. We currently have a
problem with it now. On one of our forms (frmScan, which is an unbound
form with two unbound controls) there is a txtBox contorl (txtScan)
which gets a number from a barcode put into it (usually a 9 character
varchar). I have a list box underneath this control which uses a query
as its rowsource. The trick is, I want that query to filter its data
using the specified information in the txtScan control. In access I
did this eaisly with a module and some VBA. But SQL wont let me work
like this now (or I don't know quite how to work with it now). Any
suggestions?


Nov 13 '05 #3
In some event, like the txtScan AfterUpdate event you can add this code

Private Sub txtScan_AfterUpdate()
lstScan.RowSourceType = "Table/Query"
lstScan.RowSource = Select * yourQuery WHere ScanNum = " & txtScan
Me.Requery
End Sub
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #4

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

Similar topics

2
by: DD | last post by:
I have a subform on a form In the subform i have a chkBox= and a txtbox= The idea is you Chk and the price $40.00 is automaticly entered into The chkBox has code Private Sub...
5
by: ego | last post by:
Hi all , I had created the following Form/SubForm structure : MainForm SubForm A (SubForm of MainForm) SubForm B (SubForm of SubForm A) SubForm C (SubForm of SubForm B) SubForm D ...
4
by: Shane | last post by:
I would like to update Access by using a txtBox. Is it possible to update Access this way? Example: If I selected the txtBox and input a line of text I would like that line of text to be sent...
1
by: TitanXIII | last post by:
made a little program in access that allows me to add members to a distribution list through access. I only use 4 field being 3 textbox and a command button 1 txtbox for a name 1 txtbox for...
2
by: Yin99 | last post by:
I have the code below and get the error "cannot change read only object insied a foreach loop" I am hoping someone could graciously provide code example of how I could do this? Thanks! - Yin ...
2
by: ebasshead | last post by:
Hi Everybody, I have a txtbox that populates itself when the start of the form is filled out. But sometimes I have to change the info in that specific txtbox. At the moment it wont allow me to. Is...
7
by: buddyr | last post by:
Hello, txtbox one has a date. txtbox two has a number. number is number of days) txtbox three is empty. I have alot more going on but this is my question: can I add txtbox1 + txtbox2 and show...
0
by: asmx126453 | last post by:
Hey mensen I am having some big troubles here i tryd solving it myself with internet for 2 days but i kind fix it. Its about this i have a DotNet project that alrydi is online and working for...
7
by: DefaultWorkgroup | last post by:
Good Morning Ladies and Gentleman. My question is in MS Access 2000 (I know is old, is all I have) I’m basically a Newbie in this posting of new threads and in the MS Access as well. I...
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: 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:
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
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...
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:
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
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,...

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.