Re: Display The Next Record Number on 'New Record'?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Orv (pcbidder_at_nospam.hotmal.com)
Date: 11/25/04


Date: Thu, 25 Nov 2004 08:17:28 -0500

Here is the run-time error message:

Run-time error '2147352567 (80020009)':
The value you entered isn't valid for this field.

"Orv" <pcbidder@nospam.hotmal.com> wrote in message
news:vamdnY2XHJceSjjcRVn-ow@comcast.com...
> When I click on ' Add New Record' from the Switchboard' the blank form
> shows, with focus set to 'RTFNumber' but it's filled with '00-0000'. (I
> entered 04-0001) in the table 'tblRTF' prior. Shouldn't this field on the
> new record display 04-0002? If I put in a new number, click save, I get my
> message box saying it's saved. But when I go to close the form I get a run
> time error with the following line highlighted:
>
> Me.RTFNumber = Format(Year(Date), "yy") & "-" & Str(iNum + 1)
>
> Also when I cut and paste your code, it gets ghanged to this:
> -------------------------------------------
> Private Sub Form_BeforeUpdate(Cancel As Integer)
> Dim strWhere As String
> Dim varResult As Variant
> Dim iNum As Integer
>
> If Me.NewRecord Then
> strWhere = "RTFnumber Like " & Format(Year(Date), "yy")
> varResult = DMax("RTFnumber", "tblRTF", strWhere)
>
> If Not IsNull(varResult) Then
> iNum = Val(Right(varResult, 4))
> End If
>
> Me.RTFNumber = Format(Year(Date), "yy") & "-" & Str(iNum + 1)
> End If
>
> End Sub
> ----------------------------------------------------------
>
> I also have code in 'On Current'
>
>
> Private Sub Form_Current()
>
> MeAllowEdits = False ' Return the form to its read only state.
>
> End Sub
>
> and in 'After Update':
>
> Private Sub Form_AfterUpdate()
>
> MeAllowEdits = False ' Return the form to its read only state.
> MsgBox "Record Saved."
>
> End Sub
> ----------------------------------------
> I also have a button on the form for 'Save Record', with a message box
>
> Private Sub Ctl_Save_Record_Click()
> On Error GoTo Err_Ctl_Save_Record_Click
>
>
> DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
>
> Exit_Ctl_Save_Record_Click:
> Exit Sub
>
> Err_Ctl_Save_Record_Click:
> MsgBox Err.Description
> Resume Exit_Ctl_Save_Record_Click
>
> End Sub
> ---------------------------------
> Private Sub Save_Record_Click()
> MsgBox "Record Saved."
> End Sub
> ---------------------------------
>
>
> All help is greatly appreciated!!!
>
> Orv
>
>
>
>
>


Quantcast