Avatar of allanbros
Flag for United States of America asked on

Problem with SELECT statement in VBSCRIPT

I am trying to populate a dropdown list in a label making program. The problem is I just need the first 3 characters of the column. I am pulling from a spreadsheet. Here is the code.

I think the problem is the format of my query but in any case, I can't figure this out.
datasource = "C:\Users\receiving\Desktop\tag_data\labeldata.xlsx"
intitalCatalog = "labeldata.xlsx"
tableName = "Grower$"
columnName = "GrowerName"
'userId = "Admin"
'password = ""
'Create connection

Set objCon = CreateObject("ADODB.Connection")
objCon.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" _
 & "Data Source=C:\Users\receiving\Desktop\labeldata.xlsx;" _
&"Extended Properties=""Excel 12.0;HDR=Yes;IMEX=2"""  

strCon = "SELECT LEFT(([GrowerName]),3) FROM [Grower$]"
'Run query
Set rs = CreateObject("ADODB.Recordset")
Set rs = objCon.Execute(strCon)
'Fill options
Do Until rs.EOF
        If LEN(options)>0 Then options = options + vbCR
        options = options + rs(columnName).value

'Close connection
Set objCon = Nothing
Value = options

Please help. Thank you in advance
VB ScriptMicrosoft Excel

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Thank you for the help!! This has been driving me nuts.

I am using this label making software called BarTender. I am trying to populate a drop down for the user to print labels. The software is tough to work with.

Thank you that worked really well.

Btw- If I had more than one column would I use rs=(1,2 or 3) and so on?

Yes, that is correct - in the same order as how the query is written.

Otherwise, you'd have to tap the rs.Fields(index).Name to determine which name is associated with each index.

Your help has saved me hundreds of hours of internet surfing.