LeggoMyEggo
New Member
- Joined
- Feb 15, 2011
- Messages
- 25
Hello all,
I am trying to use my program to set up an ODBC connection on the user's computer. I am trying to make it more user friendly for the other people that may want to use my file in the future, and it entirely depends on this database query.
Below is some code that I tried for executing a .bat file using Shell. The .bat file calls a .reg file that will then set up the database. It appears to run, but the database is not set up upon completion. (it works when I manually open the .bat file myself...) The contents of the .bat file is just this single line:
regedit.exe /s "scorecard.reg"
Here is my VBA:
I also know that simply setting up a delay loop is a poor practice for delaying the rest of my program, but I need some help on that as well!
The other way I tried to do this was with a shellexecute (but I think I'm calling the wrong API function..)
Thank you!
Alex
I am trying to use my program to set up an ODBC connection on the user's computer. I am trying to make it more user friendly for the other people that may want to use my file in the future, and it entirely depends on this database query.
Below is some code that I tried for executing a .bat file using Shell. The .bat file calls a .reg file that will then set up the database. It appears to run, but the database is not set up upon completion. (it works when I manually open the .bat file myself...) The contents of the .bat file is just this single line:
regedit.exe /s "scorecard.reg"
Here is my VBA:
Code:
Sub ODBCLink()
Dim ShellTest
ShellTest = Shell("S:\Services Cincinnati\Central Services Scorecards\try.bat", vbHide)
Dim x As Date
x = Now
Dim y As Long
Do Until Now > x + TimeValue("00:00:05")
y = y + 0.00000001
Loop
End Sub
I also know that simply setting up a delay loop is a poor practice for delaying the rest of my program, but I need some help on that as well!
The other way I tried to do this was with a shellexecute (but I think I'm calling the wrong API function..)
Code:
Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hWnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Sub ODBCShellExecute()
Dim filename As String
Dim result As String
filename = "D:\Documents and Settings\A27LSIT\Desktop\try.bat" '"S:\Services Cincinnati\Central Services Scorecards\try.bat"
result = ShellExecute(0&, vbNullString, filename, vbNullString, vbNullString, vbNormalFocus)
End Sub
Thank you!
Alex