BvCF
MIS
- Nov 11, 2006
- 92
Assistance needed,
Have several text box controls for data entry on my form; Amount Submit, Date Submit, Amount Received, Date Received, and Followup Date. If Amount Submit is populated, then Date Submit should not be empty and Followup Date should not be empty. If Amount Received is populated, then Date Received should not be empty.
However, the following code results in Error 91 - Object variable or with block variable not set. After researching for the past hour, I do not have a clue as to what the problem is.
Any suggestions?
Public Function RequiredData(ByVal TheForm As Form) As Boolean
'Check that select text box controls have required data entered
Dim Ctl As Control
Dim Num As Integer
On Error GoTo Err_RequiredData
RequiredData = False
'For Each Required control in the Form
Num = 0
If Ctl.Name = AmtSubmitted1 <> "" Then
If DateSubmitted1 = "" Then
Num = 1
End If
End If
'Next Ctl
If Ctl.Name = AmtSubmitted2 <> "" Then
If DateSubmitted2 = "" Then
Num = 1
End If
End If
If Ctl.Name = AmtReceived1 <> "" Then
If DateReceived1 = "" Then
Num = 1
End If
End If
If Num = 1 Then
MsgBox "Data is required in " & Ctl.Name & "," & vbCr & _
"please ensure this is entered.", _
vbInformation, "Required Data..."
RequiredData = True
Else
RequiredData = False
End If
Exit_RequiredData:
On Error Resume Next
If Not (Ctl Is Nothing) Then
Set Ctl = Nothing
End If
Exit Function
Err_RequiredData:
Select Case err
Case 0
Resume Next
Case Else
MsgBox "Error: " & err.Number & vbCrLf & vbCrLf & err.Description, _
vbInformation
End Select
End Function
Have several text box controls for data entry on my form; Amount Submit, Date Submit, Amount Received, Date Received, and Followup Date. If Amount Submit is populated, then Date Submit should not be empty and Followup Date should not be empty. If Amount Received is populated, then Date Received should not be empty.
However, the following code results in Error 91 - Object variable or with block variable not set. After researching for the past hour, I do not have a clue as to what the problem is.
Any suggestions?
Public Function RequiredData(ByVal TheForm As Form) As Boolean
'Check that select text box controls have required data entered
Dim Ctl As Control
Dim Num As Integer
On Error GoTo Err_RequiredData
RequiredData = False
'For Each Required control in the Form
Num = 0
If Ctl.Name = AmtSubmitted1 <> "" Then
If DateSubmitted1 = "" Then
Num = 1
End If
End If
'Next Ctl
If Ctl.Name = AmtSubmitted2 <> "" Then
If DateSubmitted2 = "" Then
Num = 1
End If
End If
If Ctl.Name = AmtReceived1 <> "" Then
If DateReceived1 = "" Then
Num = 1
End If
End If
If Num = 1 Then
MsgBox "Data is required in " & Ctl.Name & "," & vbCr & _
"please ensure this is entered.", _
vbInformation, "Required Data..."
RequiredData = True
Else
RequiredData = False
End If
Exit_RequiredData:
On Error Resume Next
If Not (Ctl Is Nothing) Then
Set Ctl = Nothing
End If
Exit Function
Err_RequiredData:
Select Case err
Case 0
Resume Next
Case Else
MsgBox "Error: " & err.Number & vbCrLf & vbCrLf & err.Description, _
vbInformation
End Select
End Function