Hi all,
I use access as the front-end and Oracle as the backend
I have a form that has a button; when click it, it will produce and export the result set to a excel spreadsheet.
The problem I have is that when user clicks the button, they have to manually select the datasource of the 'select data source screen' on the 'Machine Data Source' before they can see the result.
So being a novice VBA programmer, I want to code the odbc connection string in the module so that users don't have to manually select the datasource. Shown below is the code. any help would be much appreciate it.
By the way, my query is made up serveral pass-thru queries in access, so it's prompting user 2 or 3 times for the datasource before they can see the result.
Code
---------
Option Compare Database
Dim odbcConnection as new Connection
private Sub Command1_click()
Docmd.OpenQuery "Master Material Report"
Dim StrConn as String
Set odbcConnection = new Connection
StrConn = 'ODBC;DSN=a019prod;UID=priv;PWD=abc;Server=Oracle in OraHome92"
odbcConnection.connectionString = StrConn
Docmd.OutputTo acQuery, "Material Master", "MicrosoftExcel(*.xls", "C:\Mater_" & Format(Now(), "yyyymmdd" & ".xls", True, ""
set odbcConnection = Nothing
End sub
I use access as the front-end and Oracle as the backend
I have a form that has a button; when click it, it will produce and export the result set to a excel spreadsheet.
The problem I have is that when user clicks the button, they have to manually select the datasource of the 'select data source screen' on the 'Machine Data Source' before they can see the result.
So being a novice VBA programmer, I want to code the odbc connection string in the module so that users don't have to manually select the datasource. Shown below is the code. any help would be much appreciate it.
By the way, my query is made up serveral pass-thru queries in access, so it's prompting user 2 or 3 times for the datasource before they can see the result.
Code
---------
Option Compare Database
Dim odbcConnection as new Connection
private Sub Command1_click()
Docmd.OpenQuery "Master Material Report"
Dim StrConn as String
Set odbcConnection = new Connection
StrConn = 'ODBC;DSN=a019prod;UID=priv;PWD=abc;Server=Oracle in OraHome92"
odbcConnection.connectionString = StrConn
Docmd.OutputTo acQuery, "Material Master", "MicrosoftExcel(*.xls", "C:\Mater_" & Format(Now(), "yyyymmdd" & ".xls", True, ""
set odbcConnection = Nothing
End sub