New Record: Save Now Please

Randomblink

The Irreverent Reverend
Local time
Today, 08:47
Joined
Jul 23, 2001
Messages
279
Ok.
I have a form.
The purpose of the form is to generate a new report.
The user opens the form.
Selects a Client and a Borrower.
The user presses a button that assigns the REPORT NUMBER.
The number is SUPPOSED to be based on the Primary Key for the table the form is based on?

However, for the life of me, I can't get the "Me.rpt_id" field to give me ANYTHING because I am in a brand new record...

What can I do?
The VBA I use for the "ASSIGN REPORT NUMBER" button is:

Private Sub btn_AssMTSNum_Click()
Dim curDate As Variant, curYear As Variant
Dim Assign As String

curDate = Date ' First we grab the current date
curYear = Year(curDate) ' Then we grab the Year OUT of the current date
Assign = Me.Name
Assign = Me.rpt_ID & "." & Right(curYear, 2)
Me.mts_file_number.Value = Assign
Select Case Me.Dirty
Case True:
DoCmd.RunCommand acCmdSaveRecord
chkCurForm Me
Case Else:
End Select
End Sub

Help me if you can... I am just lost!
 
Here is what I did:

Private Sub btn_AssMTSNum_Click()
On Error GoTo Err_btn_AssMTSNum

Dim curDate As Variant, curYear As Variant
Dim Assign As String
Dim newRec As Boolean, dirtyFrm As Boolean
Dim rst As DAO.Recordset, test

newRec = Me.NewRecord
dirtyFrm = Me.Dirty

Set rst = Me.Recordset

curDate = Date ' First we grab the current date
curYear = Year(curDate) ' Then we grab the Year OUT of the current date

Select Case dirtyFrm
Case True:
Select Case newRec
Case True:
GoSub AssignNum
GoSub CleanForm
Case False:
GoSub CleanForm
End Select
Case False:
Select Case newRec
Case True:
GoSub MsgWarn
Case False:
GoSub CleanForm
End Select
End Select

AssignNum:
Assign = Me.rpt_ID & "." & Right(curYear, 2) ' Now we create the MTS Filenumber
Me.mts_file_number.Value = Assign
Return

CleanForm:
DoCmd.RunCommand acCmdSaveRecord
chkCurForm Me
Return

MsgWarn:
MsgBox "You need to Select a Client or a Borrower in order to Assign a MTS Number.", vbCritical, "MTS File Number"
Return


Exit_btn_AssMTSNum:
Exit Function

Err_btn_AssMTSNum:
errMessage Err
Resume Exit_btn_AssMTSNum

End Sub

It works for me...
 
Brian,

Can't it just be:

DoCmd.RunCommand acCmdSaveRecord
Me.mts_file_number = Me.rpt_ID & "." & Right(Year(Date), 2)

Wayne
 

Users who are viewing this thread

Back
Top Bottom