Generate an ODBC Connection (with a .bat)

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:

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
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,214,412
Messages
6,119,365
Members
448,888
Latest member
Arle8907

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top