Hi
I'm migrating a backend to SQL Server and a piece of my code is no longer working. The table structure is exactly the same, but it now fails when inserting a a new record to a recordset using .addnew
Here is the code:
On the line before .addnew... when hovering over '!ClientDateTypeID =', this contains a value when I assume it should be NULL
So, are .FindFirst and .NoMatch compatible when using a SQL Server back end ?
I'm migrating a backend to SQL Server and a piece of my code is no longer working. The table structure is exactly the same, but it now fails when inserting a a new record to a recordset using .addnew
Here is the code:
Code:
Public Function GenerateBlankDates(ClientType As String, ClientID As Long) As Boolean
On Error GoTo PROC_ERR
Dim db As DAO.Database
Dim rsCDT As DAO.Recordset
Dim rsCD As DAO.Recordset
Dim SQL As String
Set db = CurrentDb
SQL = "SELECT ClientDateTypeID FROM ClientDateType WHERE ClientType='" & ClientType & "'"
Set rsCDT = db.OpenRecordset(SQL, dbOpenDynaset, dbSeeChanges)
If Not rsCDT.BOF And Not rsCDT.EOF Then
rsCDT.MoveFirst
SQL = "SELECT ClientID, ClientDateTypeID, dtDate FROM ClientDates"
Set rsCD = db.OpenRecordset(SQL, dbOpenDynaset, dbSeeChanges)
Do Until rsCDT.EOF
With rsCD
rsCD.FindFirst "ClientDateTypeID=" & rsCDT!ClientDateTypeID
If rsCD.NoMatch Then
'## FAILS HERE ##
rsCD.AddNew
!ClientDateTypeID = rsCDT!ClientDateTypeID
!ClientID = ClientID
!dtDate = 0
rsCD.Update
End If
End With
rsCDT.MoveNext
Loop
GenerateBlankDates = True
Else
MsgBox "There are no ClientDateTypes for the client type: " & ClientType
End If
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox Err.Number & ": " & Err.Description
Resume Next
Resume
End Function
Code:
!ClientDateTypeID = rsCDT!ClientDateTypeID