Ashfaque
Search Beautiful Girls from your town for night
- Local time
- Today, 22:35
- Joined
- Sep 6, 2004
- Messages
- 894
Hi,
I got following DSN-Less code at Microsoft website. Since I m new to SQL Server, I have few queries.
1.
At the end it was said if I need to use the above code, after copying into a new module, I also have to use few code that is below which I have to place OnOpen event of my startup form
Private Sub Form_Open(Cancel As Integer)
If AttachDSNLessTable("authors", "authors", "(Local)", "Pubs", "", "") Then
'// All is okay.
Else
'// Not okay.
End If
End Sub
I need to ask 2 questions.
1. what value I should supply in place 2 times author, (Local) mentioned in above. I think in place of Pubs I have to provide my db name on Server.
2. In module I have replaced bold line with following
stConnect = "ODBC;DRIVER=SQL Server;SERVER=***.***.*.*;DATABASE=********;UID=**;PWD=**********"
What else do I need to add or replace so the code could run.
I got following DSN-Less code at Microsoft website. Since I m new to SQL Server, I have few queries.
1.
Code:
Function AttachDSNLessTable(stLocalTableName As String, stRemoteTableName As String, stServer As String, stDatabase As String, Optional stUsername As String, Optional stPassword As String)
On Error GoTo AttachDSNLessTable_Err
Dim td As TableDef
Dim stConnect As String
For Each td In CurrentDb.TableDefs
If td.Name = stLocalTableName Then
CurrentDb.TableDefs.Delete stLocalTableName
End If
Next
If Len(stUsername) = 0 Then
'//Use trusted authentication if stUsername is not supplied.
stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & stServer & ";DATABASE=" & stDatabase & ";Trusted_Connection=Yes"
Else
'//WARNING: This will save the username and the password with the linked table information.
stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & stServer & ";DATABASE=" & stDatabase & ";UID=" & stUsername & ";PWD=" & stPassword
End If
Set td = CurrentDb.CreateTableDef(stLocalTableName, dbAttachSavePWD, stRemoteTableName, stConnect)
CurrentDb.TableDefs.Append td
AttachDSNLessTable = True
Exit Function
At the end it was said if I need to use the above code, after copying into a new module, I also have to use few code that is below which I have to place OnOpen event of my startup form
Private Sub Form_Open(Cancel As Integer)
If AttachDSNLessTable("authors", "authors", "(Local)", "Pubs", "", "") Then
'// All is okay.
Else
'// Not okay.
End If
End Sub
I need to ask 2 questions.
1. what value I should supply in place 2 times author, (Local) mentioned in above. I think in place of Pubs I have to provide my db name on Server.
2. In module I have replaced bold line with following
stConnect = "ODBC;DRIVER=SQL Server;SERVER=***.***.*.*;DATABASE=********;UID=**;PWD=**********"
What else do I need to add or replace so the code could run.