Question : Access 2000 frontend, SQL Server 2005 tables, records changing during data entry!

We have Access 2000 frontends (ODBC System DSN) to a SQL Server 2005 table migrated from Access. While users are entering additional data into an existing record, the current record changes and the data they had entered appears in the other record! There is just 1 table in SQL Server being used, no insert query, just straight into the table.
Before the users begin to enter the data, they search for the record needed using the code snippet.

Could it be that "    strConnect = "ODBC;DSN=CompanyDSN;UID=ralph;DATABASE=companydb1;Trusted_Connection=Yes"" , with UID=ralph on each workstation in this query is causing this disaster, even though it has already run?

The System DSN being used on all PCs also has:
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\CompanyDSN]
"Driver"="C:\\WINDOWS\\system32\\SQLSRV32.dll"
"Server"="COMPANYSRV1\\SKYNET"
"Database"="companydb1"
"LastUser"="ralph"
"Trusted_Connection"="Yes"

(ralph is LastUser on all PCs)

Could this change in the query possibly fix this?:
    strConnect = "ODBC;DRIVER=SQL Server;SERVER=companysrv1\skynet;DATABASE=companydb1;Trusted_Connection=Yes"

Nothing worse than scrambled data!
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
Private Sub txtFind_AfterUpdate()
    Dim d As DAO.Database, q As DAO.QueryDef, sql As String, sQuery As String
    Dim strConnect  As String
    Dim strTextdata As String
    
    strConnect = "ODBC;DSN=CompanyDSN;UID=ralph;DATABASE=companydb1;Trusted_Connection=Yes"
 
    Set d = CurrentDb
    sQuery = "tmpQuery"
    On Error Resume Next
    DoCmd.DeleteObject acQuery, sQuery
 
    On Error GoTo errH
    Set q = d.CreateQueryDef(sQuery, sql)
    q.Connect = strConnect
 
    strTextdata = Me!txtFIND.Value
    q.sql = "Select ID From tblCompany Where [Identifier] = '" & strTextdata & "'"
    q.Close
    Set d = Nothing
    
    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "frmSQL_Finder_Search_Result"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    
    If DCount("*", "tmpQuery") = 0 Then
        DoCmd.Close acForm, "frmSQL_Finder_Search_Result"
        MsgBox "No matches found!", vbExclamation, "No matches!"
        Exit Sub
    End If
    
    Forms!CompanyForm.RecordsetClone.FindFirst "[ID] = " & Forms!frmSQL_Finder_Search_Result![txtID]
    Forms!CompanyForm.Bookmark = Forms!CompanyForm.RecordsetClone.Bookmark
 
    DoCmd.Close acForm, "frmSQL_Finder_Search"
 
    If DCount("*", "tmpQuery") = 1 Then
        DoCmd.Close acForm, "frmSQL_Finder_Search_Result"
    End If
 
    Exit Sub
    
    errH:
    MsgBox Err & " " & Err.Description
End Sub
Open in New Window Select All

Answer : Access 2000 frontend, SQL Server 2005 tables, records changing during data entry!

The format probably should be:

strConnect="ODBC;DRIVER={SQL SERVER};SERVER=companysrv1\skynet;DATABASE=companydb1;UID=;Trusted_Connection=Yes"

But you're going to need the username, so...
strConnect=strConnect1 & GetUserName() & strConnect2

Public Const strConnect1 = "ODBC;DRIVER={SQL SERVER};SERVER=companysrv1\skynet\;DATABASE=companydb1;UID="
Public Const strConnect2 = ";Trusted_Connection=Yes;Network Library=DBMSSOCN"

Public Function GetCurrentUserName() As String
On Error GoTo Err_GetCurrentUserName
 Dim lpBuff As String * 50
 Dim ret As Long, Username As String
   ret = GetUserName(lpBuff, 50)
   Username = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
   GetCurrentUserName = Username & ""

Exit_GetCurrentUserName:
    Exit Function

Err_GetCurrentUserName:
        MsgBox Err.Description
        Resume Exit_GetCurrentUserName
End Function



Random Solutions  
 
programming4us programming4us