gold007eye
Registered User.
- Local time
- Yesterday, 19:10
- Joined
- May 11, 2005
- Messages
- 260
I'm not sure what I am doing wrong, but this is the only part I am stuck on.
I am trying to use the DMax function to increment the "Extension" by +1. I am trying to do it using an IF THEN statement.
What I have it doing is when you click on the "Add Reassignment" button it adds a new record and copies the previous record information "BaseID", "Extension", & "SSNEIN" to the new record. I then have the code to look and see if the "Extension" field is NULL and if so it Then the "Extension" field = the "Starting Extension" value "01" from the Main Form.
Where I am running into my problem is the 2nd portion of the statement that needs to update the Extension field to the next number if the extension field is NOT NULL.
Here is the code I am using.
This Code throws no errors, but gives the results you see in the attached picture:
If I use this code it throws an error saying "Compile Error: Argument Not Optional" and highlights "DMax":
What am I doing wrong?
I am trying to use the DMax function to increment the "Extension" by +1. I am trying to do it using an IF THEN statement.
What I have it doing is when you click on the "Add Reassignment" button it adds a new record and copies the previous record information "BaseID", "Extension", & "SSNEIN" to the new record. I then have the code to look and see if the "Extension" field is NULL and if so it Then the "Extension" field = the "Starting Extension" value "01" from the Main Form.
Where I am running into my problem is the 2nd portion of the statement that needs to update the Extension field to the next number if the extension field is NOT NULL.
Here is the code I am using.
This Code throws no errors, but gives the results you see in the attached picture:
Code:
Private Sub Add_Reassignment_Click()
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
Me![BaseID] = .Fields("BaseID")
Me![SSNEIN] = .Fields("SSNEIN")
If IsNull([Extension]) Then
Me![Extension] = Format([Forms]![New Provider]![Starting Extension], "00")
Else:
Me![Extension] = Format(Nz(DMax("[Extension]", "[Provider Number Information]"), 0) + 1)
End If
Me![Provider Number] = Format([BaseID], "0000000") & Format([Extension], "00")
End With
End If
End Sub
If I use this code it throws an error saying "Compile Error: Argument Not Optional" and highlights "DMax":
Code:
Private Sub Add_Reassignment_Click()
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
Me![BaseID] = .Fields("BaseID")
Me![SSNEIN] = .Fields("SSNEIN")
If IsNull([Extension]) Then
Me![Extension] = Format([Forms]![New Provider]![Starting Extension], "00")
Else:
Me![Extension] = Format(Nz(DMax([Extension]), 0) + 1)
End If
Me![Provider Number] = Format([BaseID], "0000000") & Format([Extension], "00")
End With
End If
End Sub