Group:  Microsoft Access ยป microsoft.public.access.gettingstarted
Thread: Run Time Error 3314

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

Run Time Error 3314
Sue Wilkes 14.07.2006 13:55:01
I have a table HYInReg in which the field "RegisterNumber" is set as Text and
is required and uses the following code:-

Private Sub RegisterNumber_Click()

If Me.NewRecord Then
Dim strWhere As String
Dim varResult As Variant

strWhere = "RegisterNumber Like """ & Format(Date, "yy") & "*"""
varResult = DMax("RegisterNumber", "HYInReg", strWhere)

If IsNull(varResult) Then
Me.RegisterNumber = Format(Date, "yy") & "-000001"
Else
Me.RegisterNumber = Left(varResult, 3) & _
Format(Val(Right(varResult, 4)) + 1, "000000")
End If
End If
End Sub

On my form "RegEntryForm" which is used for data entry (add only) I have a
print button which uses the following code:-

Private Sub cmdPrint_Click()
Dim StrDocName As String
Dim strWhere As String

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[RegisterNumber]=""" & Me.[RegisterNumber] & """"
DoCmd.OpenReport "RegEntryFormRpt", acViewPreview, , strWhere
End If
End Sub

If the button is selected without the Register Number field being populated
then the following RUN TIME ERROR 3314 message appears. If I end this and
populate the field then select the print button all is works. However
instead of the error message I would like a reminder (messagebox) to appear
reminding the user to click on the RegisterNumber field which then gives you
the Register Number. Any help to this very green novice would be greatly
appreciated.
RE: Run Time Error 3314
Klatuu 14.07.2006 19:56:02
Check for a value before you print.

Private Sub cmdPrint_Click()
Dim StrDocName As String
Dim strWhere As String

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
If IsNull(Me.[RegisterNumber]) Then
MsgBox "A Register Number is Required"
Me.[RegisterNumber].SetFocus
Else
strWhere = "[RegisterNumber]=""" & Me.[RegisterNumber] & """"
DoCmd.OpenReport "RegEntryFormRpt", acViewPreview, , strWhere
End If
End If
End Sub


"Sue Wilkes" wrote:

[Quoted Text]
> I have a table HYInReg in which the field "RegisterNumber" is set as Text and
> is required and uses the following code:-
>
> Private Sub RegisterNumber_Click()
>
> If Me.NewRecord Then
> Dim strWhere As String
> Dim varResult As Variant
>
> strWhere = "RegisterNumber Like """ & Format(Date, "yy") & "*"""
> varResult = DMax("RegisterNumber", "HYInReg", strWhere)
>
> If IsNull(varResult) Then
> Me.RegisterNumber = Format(Date, "yy") & "-000001"
> Else
> Me.RegisterNumber = Left(varResult, 3) & _
> Format(Val(Right(varResult, 4)) + 1, "000000")
> End If
> End If
> End Sub
>
> On my form "RegEntryForm" which is used for data entry (add only) I have a
> print button which uses the following code:-
>
> Private Sub cmdPrint_Click()
> Dim StrDocName As String
> Dim strWhere As String
>
> If Me.Dirty Then 'Save any edits.
> Me.Dirty = False
> End If
>
> If Me.NewRecord Then 'Check there is a record to print
> MsgBox "Select a record to print"
> Else
> strWhere = "[RegisterNumber]=""" & Me.[RegisterNumber] & """"
> DoCmd.OpenReport "RegEntryFormRpt", acViewPreview, , strWhere
> End If
> End Sub
>
> If the button is selected without the Register Number field being populated
> then the following RUN TIME ERROR 3314 message appears. If I end this and
> populate the field then select the print button all is works. However
> instead of the error message I would like a reminder (messagebox) to appear
> reminding the user to click on the RegisterNumber field which then gives you
> the Register Number. Any help to this very green novice would be greatly
> appreciated.

Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net