|
-
Sep 27th, 2007, 11:13 PM
#1
Thread Starter
New Member
[RESOLVED]problem passing arguments from access to vbs
hi everyone,
I want to use vb scripts to execute query in database access. In the database, I have a combo box for user to select a customer as a condition for the query. I have a problem to pass the selection from the database as arguement to vb script. Here is my code:
code in database:
Private Sub Command82_Click()
If dropdown.ItemData(dropdown.ListIndex) <> vbNullString Then
Dim selectCustomer As String
selectCustomer = CStr(dropdown.ItemData(dropdownReprice.ListIndex))
ShellWait ("wscript D:\SHUT_DOWN_CUSTOMER.vbs")
Else
MsgBox "Please select a Customer"
End If
End Sub
code in vbs:
Dim arg
arg = selectCustomer
SHUT_DOWN = "UPDATE Main SET Enabled = 0 WHERE Enabled = 1 And Customer = '" & arg & "'"
set cl = db.Execute(SHUT_DOWN)
How can pass an arguement as selectCustomer to vb script?
Thanks
Last edited by NJman; Sep 28th, 2007 at 11:00 PM.
-
Sep 28th, 2007, 07:44 AM
#2
Re: problem passing arguments from access to vbs
i guess you pass the argument with the script
ShellWait ("wscript D:\SHUT_DOWN_CUSTOMER.vbs" selectcustomer)
if the string could contain spaces it would need to be enclosed in quotes
ShellWait ("wscript D:\SHUT_DOWN_CUSTOMER.vbs" """" & selectcustomer & """")
in the script
arg = wscript.arguments()
i have not tested this
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Sep 28th, 2007, 06:44 PM
#3
Thread Starter
New Member
Re: problem passing arguments from access to vbs
hi Pete,
Thanks for your help, I got it work. However, I had to add the arguments(selectCustomer) in the script to make it work.
It still doesn't work if the string contains spaces
ShellWait ("wscript D:\SHUT_DOWN_CUSTOMER.vbs" """" & selectcustomer & """")
It works only for string has no space in it.
I still have to think how can it work for string includes space in it.
-
Sep 28th, 2007, 07:16 PM
#4
Re: problem passing arguments from access to vbs
i tested this from excel i don't know what you are using for shellwait, so i just use shell
vb Code:
selectcustomer = """" & "pete hall" & """"
ret = Shell("wscript.exe ""C:\Documents and Settings\peter\My Documents\basic\vbs\scrtest.vbs"" " & selectcustomer, vbNormalNoFocus)
vb Code:
arg = wscript.arguments(0)
wscript.echo arg
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Sep 28th, 2007, 10:51 PM
#5
Thread Starter
New Member
Re: problem passing arguments from access to vbs
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|