Run Time Error 3314

G

Guest

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.
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Back to Basics 1
Number+1 12
Building a record ID 8
Data Validation from Delete Command Button 1
Previous Command No Longer Works 2
Reset text box to zero 6
Main Form, Sub-Form 3
Modify Message Box Cancel Button 6

Top