I have been looking through my code for hours trying to see what, if anything, I did. This was working fine yesterday and just decided it didn't want to anymore. Can someone check to see if they can spot what's wrong? I'm using a class to upload data to a table.
The error occurs during the the Update method in the class. It begins and applies the table primary key (ProjectId), but immediately fails with the error as it exits the Get ClientId() property.
Any help would be GREATLY appreciated!!!!
Class
clsProject
Code:
Option Compare Database
Option Explicit
Private plProjectId As Long
Private plClientId As Long
Private plClientContactId As Long
Private plOwnerId As Long
Private psProjectNumber As String
Private prsRecordset As Recordset
Private pbLoaded As Boolean
Public Property Get ProjectId() As Long
ProjectId = plProjectId
End Property
Public Property Get ClientId() As Long
ClientId = plClientId
End Property
Public Property Get ClientContactId() As Long
ClientContactId = plClientContactId
End Property
Public Property Get OwnerId() As Long
OwnerId = plOwnerId
End Property
Public Property Get ProjectNumber() As String
ProjectNumber = psProjectNumber
End Property
Public Property Get Recordset() As Recordset
Set Recordset = prsRecordset
End Property
' Class Let Properties
Public Property Let ProjectId(lProjectId As Long)
plProjectId = lProjectId
End Property
Public Property Let ClientId(lClientId As Long)
plClientId = lClientId
End Property
Public Property Let ClientContactId(lClientContactId As Long)
plClientContactId = lClientContactId
End Property
Public Property Let OwnerId(lOwnerId As Long)
plOwnerId = lOwnerId
End Property
Public Property Let ProjectNumber(sProjectNumber As String)
psProjectNumber = sProjectNumber
End Property
' Class Set properties
Public Property Set Recordset(rData As Recordset)
Set prsRecordset = rData
End Property
' Class Methods
Public Function FindFirst(Optional Criteria As Variant) As Boolean
If IsMissing(Criteria) Then
Recordset.MoveFirst
FindFirst = Not Recordset.EOF
Else
Recordset.FindFirst Criteria
FindFirst = Not Recordset.NoMatch
End If
If FindFirst Then Load
End Function
Function EmptyStringHandler(str As String) As Variant
Dim strTrimmed As String: strTrimmed = Trim(str)
If Len(strTrimmed) = 0 Then
EmptyStringHandler = Null
Else
EmptyStringHandler = strTrimmed
End If
End Function
Private Sub Class_Initialize()
Set Recordset = CurrentDb.OpenRecordset("Project", dbOpenDynaset)
End Sub
Private Sub Class_Terminate()
Recordset.Close
Set Recordset = Nothing
End Sub
Private Sub Load()
With Recordset
ProjectId = Nz(.Fields("ProjectId").Value)
Me.ClientId = Nz(.Fields("ClientId").Value)
Me.ClientContactId = Nz(.Fields("ClientContactId").Value)
Me.OwnerId = Nz(.Fields("ProjectOwnerId").Value)
Me.ProjectNumber = Nz(.Fields("ProjectNumber").Value)
End With
pbLoaded = True
End Sub
Public Sub Update()
With Recordset
If pbLoaded = True Then
.Edit
Else
.AddNew
End If
Me.ProjectId = Nz(.Fields("ProjectId").Value)
Nz(.Fields("ClientId").Value) = CLng(Me.ClientId)
Nz(.Fields("ClientContactId").Value) = Me.ClientContactId
Nz(.Fields("OwnerId").Value) = Me.OwnerId
Nz(.Fields("ProjectNumber").Value) = EmptyStringHandler(Me.ProjectNumber)
.Update
End With
pbLoaded = True
End Sub
Public Sub AddNew()
pbLoaded = False
End Sub
The calling procedure results in a cmdSave_Click() event (miEditMode is a module level variable tracking the mode the form is in (New, Edit, View) ).
Code:
Private Sub cmdSave_Click()
Dim cProject As clsProject
Set cProject = New clsProject
With cProject
Select Case miEditMode
Case 1
.AddNew
Case 2
.FindFirst "ProjectId=" & .ProjectId
End Select
.ClientId = CLng(cboProjectClient.Column(0, cboProjectClient.ListIndex))
.ClientContactId = CLng(cboClientContact.Column(0, cboClientContact.ListIndex))
.OwnerId = CLng(cboProjectOwner.Column(0, cboProjectOwner.ListIndex))
.ProjectNumber = txtProjectNumber
.Update
End With
End Sub