Pass argument from command button on Access form to python script
Question: Using Access 2010 and python 2.7.8

Have a command button on Access 2010 form. I am trying to pull the value from
the Field1 text box and pass it to a python script. I am struggling with
passing the variable. Commented out stuff is other things I tried.

Value in Field1 Text box is:

    
    
    C:\\tests\\Project
    

VBA behind command button:

    
    
    Private Sub Command0_Click()
        arg1 = """" & Field1 & """"
        'arg1 = Field1
      Debug.Print arg1
        'Call Shell("C:\\Python27\\ArcGIS10.3\\python.exe " & "C:\\tests\\Test.py " & "C:\\tests\\Project", vbNormalFocus)
        Call Shell("C:\Python27\ArcGIS10.3\python.exe " & "C:\tests\Test.py " & arg1, vbNormalFocus)
    End Sub
    

Python code is:

    
    
    import os.path
    
    #fp = "C:\\tests\\Projects"
    fp = argv[1]
    os.makedirs(fp)
    


Answer: Try the following in Python

    
    
    # should be sys.argv[1]
    sys.argv[1]
    

You may want to utilise os.path.join to be certain where your makedirs are
going

    
    
    import os
    import sys
    
    sys.argv[1]
    fp = r'c:\test'
    os.makedirs(os.path.join(fp,sys.argv[1]))
    

**THE VBA in Excel** \- works for me...

    
    
    Private Sub test()
        arg1 = Range("A1").Value
        Debug.Print arg1
        Call Shell("""C:\Python27\python.exe"" " & """c:\test\test.py"" " & """arg1""", vbNormalFocus)
    End Sub 
    

