I have the DSN-Less connection code as follows that I got from the mircosoft site......
Option Compare Database
'//Name : AttachDSNLessTable
'//Purpose : Create a linked table to SQL Server without using a DSN
'//Parameters
'// stLocalTableName: Name of the table that you are creating in the current database
'// stRemoteTableName: Name of the table that you are linking to on the SQL Server database
'// stServer: Name of the SQL Server that you are linking to
'// stDatabase: Name of the SQL Server database that you are linking to
'// stUsername: Name of the SQL Server user who can connect to SQL Server, leave blank to use a Trusted Connection
'// stPassword: SQL Server user password
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
AttachDSNLessTable_Err:
AttachDSNLessTable = False
MsgBox "AttachDSNLessTable encountered an unexpected error: " & Err.Description
End Function
I then put this code in the on_open form.................
Private Sub Form_Open(Cancel As Integer)
Dim ServerName As String
Dim UserName As String
Dim Password As String
ServerName = "CPS23"
UserName = "myUserName"
Password = "myPassword"
'Attach the linked database tables if they aren't already attached
AttachDSNLessTable "dbo_AncillaryEquipUsed", "AncillaryEquipUsed", ServerName, "ABCFieldTicket", UserName, Password
End Sub
As far as connecting or linking the back-end SQL Server tables this code works great. My question is that I am having issues with access or security. Anyone that can find the .mdb file can get in and enter data into this system. How do I (or the SQL Administrator) set it up to where what security user group that is on the server is also on the front-end MS Access file? If someone is NOT in the user group then they should not be allowed to enter data into the system. So maybe have a window pop-up asking for a username and password? Not sure, but any pointers or any kind of help would be greatly appreciated.