Private Sub CreateSQLODBC()
' This function setups a DSN common for remote Database servers
' Such as SQL or Oracle, keep in mind, this isnt a complete listing of parameters
Dim DSN As String
Dim Server As String
Dim Address As String
Dim Database As String
Dim Description As String
Dim Security As String
'Basically the DSN Name you want to have
DSN = "DSN=" & Trim(txtDatabase.Text)
'The IP Addy of the server you want , if this is a remote connection
Server = "SERVER=" & Trim(txtServer.Text)
'Same as above
Address = "ADDRESS=" & Trim(txtServer.Text)
'The name of the database as known by the DB Server, such as SQL Server
Database = "DATABASE=" & Trim(txtDatabase.Text)
'An Optional Description Feild
Description = "DESCRIPTION=" & Trim(txtDescription.Text)
'This is optional, if you require a Security mode check the help files
Security = "NETWORK=dbmssocn"
'the next couple lines setup the Driver Text , that defines the type of DB Drivers
' you are using, if its anything other than the ones I've listed, check your DB
' documentation, or check the ODBC settings to see it's names
'Also you will notice as each string peice is put together, they are seperated by
'VbNullChar, this gives it a Null seperated array in a sense so that the API Command
'can use the Parameters
If OptSQL.Value = True Then
SqlDriver = "SQL Server"
SQLParameter = DSN & vbNullChar & Server & vbNullChar & Address & vbNullChar & Security & vbNullChar & _
Database & vbNullChar & Description & vbNullChar & vbNullChar
ElseIf OptOracle.Value = True Then
SqlDriver = "Oracle73"
SQLParameter = DSN & vbNullChar & Server & vbNullChar & Database & vbNullChar & _
Description & vbNullChar & vbNullChar
End If
'calls SQLConfigDataSource , giving it the forms handle, the command to Add a System DSN
'giving it the Driver name, and then the Null Seperated Parameter listing
SQLConfigDataSource 0&, ODBC_ADD_SYS_DSN, SqlDriver, SQLParameter
'Replace 0& with Me.hwnd if you wish for users to further configure settings such as a long
End Sub
Private Sub CreateAccessODBC()
'This common setup for an Access Database
Dim Driver As String
Dim DSN As String
Dim Server As String
Dim Database As String
Dim Description As String
DSN = "DSN=" & Trim(AccessDSNtxt.Text)
Database = "DBQ=" & Trim(AccessDBQTxt.Text) 'this is your physical path to the *.mdb
Description = "DESCRIPTION=" & Trim(AccessDesc.Text)
AccessParameter = DSN & vbNullChar & Database & vbNullChar & Description & vbNullChar & vbNullChar
SQLConfigDataSource 0&, ODBC_ADD_SYS_DSN, "Microsoft Access Driver (*.mdb)", AccessParameter
End Sub
Private Sub CreateAccess_Click()
CreateAccessODBC
End Sub
Private Sub CreateServer_Click()
CreateSQLODBC
End Sub