Results 1 to 5 of 5

Thread: [RESOLVED]problem passing arguments from access to vbs

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2007
    Posts
    4

    Resolved [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.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2007
    Posts
    4

    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.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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:
    1. selectcustomer = """" & "pete hall" & """"
    2. ret = Shell("wscript.exe ""C:\Documents and Settings\peter\My Documents\basic\vbs\scrtest.vbs"" " & selectcustomer, vbNormalNoFocus)


    vb Code:
    1. arg = wscript.arguments(0)
    2. 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

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2007
    Posts
    4

    Re: problem passing arguments from access to vbs

    Thanks Pete. It works

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width