473,395 Members | 1,526 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,395 software developers and data experts.

Auto - Start Code

Hello,
I have a form that will be used to display data from a table using 'Dlookup' based on what is entered into a textbox. I can get it to work by callng the code via a form button, but wanted to know if there is a way to call the code without having to use a button. I will be using a barcode scanner to read the data to be queried on but I don't want the end-user to have to scan their barcode and then click a form button but rather just scan the barcode and it automatically initiate the 'Dlookup' code.

Thanks for your help.
Feb 16 '08 #1
8 2338
Megalog
378 Expert 256MB
Hello,
I have a form that will be used to display data from a table using 'Dlookup' based on what is entered into a textbox. I can get it to work by callng the code via a form button, but wanted to know if there is a way to call the code without having to use a button. I will be using a barcode scanner to read the data to be queried on but I don't want the end-user to have to scan their barcode and then click a form button but rather just scan the barcode and it automatically initiate the 'Dlookup' code.

Thanks for your help.
Not sure how you have this set up, but have you tried shifting the code from the button, to the "On Change" event of the text field? That might trigger it everytime it's updated via the scanner.
Feb 16 '08 #2
Not sure how you have this set up, but have you tried shifting the code from the button, to the "On Change" event of the text field? That might trigger it everytime it's updated via the scanner.
Thanks, I tried that and I get the following error:
"Run- time error '3075':
Syntax error (missing operator) in query expression 'ID = '."

Below is the code I am using:

Expand|Select|Wrap|Line Numbers
  1.  Private Sub CODE_Change() 
  2. Dim BAR, NAME
  3. BAR = CODE.Value
  4. NAME = DLookup("NAME", "TBL_NAME", "ID = " & (BAR) & "")
  5. FIRST.Value = NAME
  6. End Sub
  7.  
CODE.value is the text box that the scanner is inputting the data.
FIRST.value is the text box that will display the queried data from the DLookup.

Any ideas?
Feb 16 '08 #3
ADezii
8,834 Expert 8TB
Thanks, I tried that and I get the following error:
"Run- time error '3075':
Syntax error (missing operator) in query expression 'ID = '."

Below is the code I am using:

Private Sub CODE_Change()
Dim BAR, NAME
BAR = CODE.Value
NAME = DLookup("NAME", "TBL_NAME", "ID = " & (BAR) & "")
FIRST.Value = NAME
End Sub

CODE.value is the text box that the scanner is inputting the data.
FIRST.value is the text box that will display the queried data from the DLookup.

Any ideas?
Try:
[code=vb]
Private Sub CODE_Change()
'If [ID] is Text
Me![FIRST] = DLookup("[<Lookup Field in Table>]", "TBL_NAME", "ID = '" &
Me![code] & "'")

'If [ID] is Numeric
Me![FIRST] = DLookup("[<Lookup Field in Table>]", "TBL_NAME", "ID = " &
Me!
Expand|Select|Wrap|Line Numbers
  1. )
  2. End Sub
Feb 17 '08 #4
Try:
[code=vb]
Private Sub CODE_Change()
'If [ID] is Text
Me![FIRST] = DLookup("[<Lookup Field in Table>]", "TBL_NAME", "ID = '" &
Me![code] & "'")

'If [ID] is Numeric
Me![FIRST] = DLookup("[<Lookup Field in Table>]", "TBL_NAME", "ID = " &
Me!
Expand|Select|Wrap|Line Numbers
  1. )
  2. End Sub

Thanks, although still get the same error.
Feb 17 '08 #5
missinglinq
3,532 Expert 2GB
Can we see an exact copy of the code you tried last?

Linq ;0)>
Feb 17 '08 #6
Can we see an exact copy of the code you tried last?

Linq ;0)>
Sure thing.
[code=VB]Private Sub CODE_Change()
Me![FIRST] = DLookup("name", "tbl_name", "id = " & Me!
Expand|Select|Wrap|Line Numbers
  1.  & "")
  2. End Sub
Thanks
Feb 17 '08 #7
missinglinq
3,532 Expert 2GB
You've left out some single quotes from around the Criteria in ADezii's code. Instead of

[code=vb]Me![FIRST] = DLookup("name", "tbl_name", "id = " & Me!
Expand|Select|Wrap|Line Numbers
  1.  & "")
  2.  
it should be

[code=vb]Me![FIRST] = DLookup("name", "tbl_name", "id = '" & Me!
Expand|Select|Wrap|Line Numbers
  1.  & "'")
  2.  
if id is text.

Also, if you actually have a field named Name in your table, as your code indicates, you really have to change this! Name is a Reserved Word in Access , and a very important one, because it's the name of an Objects Property!

Me.ProductName.Visible = False

will make a control named ProductName invisible, but

Me.Name.Visible = False

will throw an error, as will any other property you try to access.

Linq ;0)>
Feb 17 '08 #8
Thank you to all those who helped me with this. I was able make it work by using a 2nd form. The issue with the error is becasue even though the textbox named CODE had a value in it from the barcode scanner, Access did not see the value until that textbox lost focus. To make it work, on the On Change event for textbox CODE I had it set focus on another textbox named Text5. Then using the On Enter event on Text5, set it to open a new form called Form2. Then using the On Open event on Form2 I called back to the first form and was able to get the value out of the CODE textbox and do my Dlookup line. I know this is a lot of steps but it worked. Apparently it all boiled down to getting the focus off the that CODE textbox so that Acces could see the value it in.

Thanks again.
Feb 17 '08 #9

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

Similar topics

3
by: Jonathan | last post by:
Hi all: I originally posted this in an HTML forum, but have realized that the solution may (a) require a server-side change or (b) be non-existent. In any case, since the page I'm dealing with is...
7
by: Brian | last post by:
hello, I am looking for a way to auto refresh a web page that I created, but also let the user choose to stop the auto refresh. I can not figure out how to stop the auto refresh. Any help would...
4
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hi... Following the samples online, we implemented a windows service in .Net. Like most services, there's a worker thread actually doing stuff in the background. The problem we've run into is...
27
by: Harris Kosmidhs | last post by:
Hello. sorry if this has been answered previously. I use a main wrapper div to put the whole site in it. And I use margin: 0 auto 0 auto in order to center the page. But in IE it fails. Is...
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
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
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
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...

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.