Hiding button

B

Bill Neilsen

I have a form with multiple fields and a button which prints a report of the
current record.

I'm having all sorts of difficulties ensuring that all fields are completed
before the report is printed.

Is it possible to hide the button untill all fields are completed?

If so, can anyone show me the code please?
 
A

Allen Browne

1. Open your table in design view. For each field where the user *must*
enter something, set its Required property (lower pane in table design) to
Yes. Now they won't be able to save the record until they fill those fields
in.

2. For the fields where you want to provide a warning, use the BeforeUpdate
event of the *form* to test if your fields are null. Example:

Private Sub Form_BeforeUpate(Cancel As Integer)
Dim strMsg As String
If IsNull(Me.Surname) Then
strMsg = strMsg & "Surname is blank" & vbCrLf
End If
If IsNull(Me.City) Then
strMsg = strMsg & "City is blank" & vbCrLf
End If
'etc for other fields.
If strMsg <> vbNullString Then
strMsg = strMsg & vbCrLf & "Proceed anyway?"
If MsgBox(strMsg, vbYesNo+vbDefaultButton2) <> vbYes Then
Cancel = True
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

Top