Technical support and scripting issues
Moderators: JRL, Dorian (MJT support)
-
IKnowNothing
- Newbie
- Posts: 2
- Joined: Thu Feb 24, 2011 1:38 am
- Location: Boca Raton, FL USA
Post
by IKnowNothing » Thu Feb 24, 2011 1:59 am
Please Help.
I need to query an excel file for the Name given the AccountNumber.
Then display the Name in a message box onscreen.
I think I am either not connected to the Excel file , or not successfully passing values between arrays and variables from search results.
Is there an easy way to test a DBConnection?
Also, here is my Excel data
EXCEL FILE CONTENTS:
Name AccountNumber
Electric 500
Building Maint 1000
Water 2000
Painting 3000
Landscaping 4000
Office Expenses 5000
Code: Select all
[code]
//Connect to Datasource
DBConnect>Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Users\My\Desktop\Accounts.xls; Extended Properties=â€
Total Business Solutions, Inc.
-
Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
-
Contact:
Post
by Marcus Tettmar » Thu Feb 24, 2011 9:25 am
Is there an easy way to test a DBConnection?
Yes, use the debugger. Step past the DBConnect line and look at the return value.
-
JRL
- Automation Wizard
- Posts: 3532
- Joined: Mon Jan 10, 2005 6:22 pm
- Location: Iowa
Post
by JRL » Thu Feb 24, 2011 9:56 pm
I don't know where you found the connection string you're using but it has some issues. First remove the spaces between the semicolon delimited parameters. Then remove the quotes around Excel etc. Then eliminate the Header exists parameter. I don't think that works with excel.
Then in you SQL string, since you are requesting a number as user input, the %myval% variable cannot have quotes around it.
The following works for me
Code: Select all
//Connect to Datasource
DBConnect>Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\My\Desktop\Accounts.xls;Extended Properties=Excel 8.0;,dbH
//Display Input Ask User For Account Number
Input>myval,What is the Account Number to search?
//Perform SELECT query
Let>SQL=select NAME from [Sheet1$] where AccountNumber=%myval%
DBQuery>dbh,SQL,Sheet1Results,numrecs,numfields
//Display message with Name of AccountNumber
Message>'%Sheet1Results_1_1%'
//Close database connection
DBClose>dbH
-
IKnowNothing
- Newbie
- Posts: 2
- Joined: Thu Feb 24, 2011 1:38 am
- Location: Boca Raton, FL USA
Post
by IKnowNothing » Sat Feb 26, 2011 3:45 pm
Thanks for the timely response.
It now works.
Keep up the good work.
Total Business Solutions, Inc.