gold007eye
Registered User.
- Local time
- Today, 16:18
- Joined
- May 11, 2005
- Messages
- 260
How do I use IF statements within an Existing IF statement to accomplish different outcomes? I have been trying different code for a while now and can't seem to get it to do what I want it to.
Here is what I want the code to do.
1st - if the field "Provider Number" conists of 6 or 8 characters then start the
1st paragraph of code for that criteria.... afterwhich if the "extension"
field is still NULL then run the If IsNull code. Otherwise if
the "extension" field is NOT NULL after the 1st paragraph of code has
been run for this criteria; then run the 1st ElseIf code for this criteria.
2nd - if the field "Provider Number" conists of 7 or 9 characters then start
the 1st paragraph of code for that criteria.... afterwhich if
the "extension" field is still NULL then run the If IsNull code. Otherwise
if the "extension" field is NOT NULL after the 1st paragraph of code has
been run for this criteria; then run the 1st ElseIf code for this criteria.
Can someone tell me what I am doing wrong or how I should go about this?
Here is what I want the code to do.
1st - if the field "Provider Number" conists of 6 or 8 characters then start the
1st paragraph of code for that criteria.... afterwhich if the "extension"
field is still NULL then run the If IsNull code. Otherwise if
the "extension" field is NOT NULL after the 1st paragraph of code has
been run for this criteria; then run the 1st ElseIf code for this criteria.
2nd - if the field "Provider Number" conists of 7 or 9 characters then start
the 1st paragraph of code for that criteria.... afterwhich if
the "extension" field is still NULL then run the If IsNull code. Otherwise
if the "extension" field is NOT NULL after the 1st paragraph of code has
been run for this criteria; then run the 1st ElseIf code for this criteria.
Can someone tell me what I am doing wrong or how I should go about this?
Code:
Private Sub Add_Reassignment_Click()
On Error GoTo Add_Reassignment_Click_Err
DoCmd.GoToRecord , , acNewRec
Dim rs As Object
Set rs = Me.Recordset.Clone
If rs.EOF Or Not Me.NewRecord Then
' don't do anything if there's no records or it is not a new record
Else
With rs
.MoveLast
If Len([Forms]![Existing SSN]![Provider Number]) = 7 Or 9 Then
Me![BaseID] = .Fields("BaseID")
Me![SSN] = .Fields("SSN")
Me![Extension] = .Fields("Extension")
Me![SFDate] = Now()
Forms![Existing SSN]![TimeStamp] = Time()
Forms![Existing SSN]![TimeStamp].Requery
If IsNull([Extension]) Then
Me![Extension] = [Forms]![Existing SSN]![Starting Extension]
Me![Provider Number] = Format([BaseID], "0000000") & Format([Extension], "00")
DoCmd.RunCommand acCmdSaveRecord
ElseIf Len([Forms]![Existing SSN]![Provider Number]) = 7 Or 9 And _
Me![Extension] = Not Null Then
Me![Extension] = Format(Nz(DMax("[Extension]", "[Provider Number Information]", "[Starting Extension]" = Forms![Existing SSN]![Starting Extension]), [Extension]) + 1)
Me![Provider Number] = Format([BaseID], "0000000") & Format([Extension], "00")
DoCmd.RunCommand acCmdSaveRecord
End If
ElseIf Len([Forms]![Existing SSN]![Provider Number]) = 6 Or 8 Then
Me![SSN] = .Fields("SSN")
Me![Extension] = .Fields("Extension")
Me![SFDate] = Now()
Forms![Existing SSN]![TimeStamp] = Time()
Forms![Existing SSN]![TimeStamp].Requery
If IsNull([Extension]) Then
Me![Extension] = [Forms]![Existing SSN]![Starting Extension]
Me![Provider Number] = Forms![Existing SSN]![Provider Number] & Format([Extension], "00")
DoCmd.RunCommand acCmdSaveRecord
ElseIf Len([Forms]![Existing SSN]![Provider Number]) = 6 Or 8 And _
Me![Extension] = Not Null Then
Me![Extension] = Format(Nz(DMax("[Extension]", "[Provider Number Information]", "[Starting Extension]" = Forms![Existing SSN]![Starting Extension]), [Extension]) + 1)
Me![Provider Number] = Forms![Existing SSN]![Provider Number] & Format([Extension], "00")
DoCmd.RunCommand acCmdSaveRecord
End If
End If
Forms![Existing SSN]![Provider Number] = [Provider Number]
Forms![Existing SSN]![Provider Number].Requery
Me![Dummy].SetFocus
End With
End If
Add_Reassignment_Click_Exit:
Exit Sub
Add_Reassignment_Click_Err:
If Err = 2113 Then 'Add Reassignment Button was clicked too fast
DoCmd.RunCommand acCmdUndo
Exit Sub
ElseIf Err = 2105 Then 'Can't go to specified record
DoCmd.RunCommand acCmdUndo
Exit Sub
ElseIf Err = 3163 Then 'Record Extension 99 has been reached
MsgBox "This provider number can't have anymore extensions..." & vbCrLf & vbCrLf & "99 is the maximum number of allowable reassignments!", vbExclamation, "99 Reassignments Reached..."
DoCmd.RunCommand acCmdUndo
Exit Sub
Else
MsgBox Err.Number & " - " & Err.Description
Resume Add_Reassignment_Click_Exit
End If
End Sub