No error message when required field left blank?

G

Guest

Hello,

I have a series of forms in a database that I progress thru by clicking on a
'Next' Command Button present on the form that opens up the next form in the
series based the 'id' field in the 'initial' form ('fScrEligCriteria') in the
series (see code below):

Private Sub Next_Click()

On Error GoTo Err_Next_Click

Call OpenNextForm(Me.Name)

Exit_Next_Click:
Exit Sub

Err_Next_Click:
DoCmd.Close acForm, Me.Name
Resume Exit_Next_Click

End Sub

Sub OpenNextForm(strName As String)
Dim intOrder As Integer, frmName As String

On Error GoTo OpenNextForm_Err

intOrder = DLookup("[FormOrder]", "LU_Forms", "[FormName]= '" & strName
& "'")
frmName = DLookup("[FormName]", "LU_Forms", "[FormOrder]= " & intOrder
+ 1)
If Not IsNull(frmName) Then
DoCmd.OpenForm frmName, , , "[id] = Forms.fScrEligCriteria.id"
'DoCmd.OpenForm frmName, , , , acAdd
End If
DoCmd.Close acForm, strName

OpenNextForm_Err:
'MsgBox Err.Description
Resume Next

End Sub

It works great, but the thing is that if a required field is not filled out,
hitting next still allows the user to progress to the next form and does not
alert the data entry person that a required field has not been filled out.
It does not save the record in the underlying table (which is good). I
un-commented out the error section of the code in the OpenNextForm sub:

OpenNextForm_Err:
'MsgBox Err.Description
Resume Next

but, all is says is 'Object doesn't support this property or method'-- which
I'm not sure why this error message comes up, since data entry into this
database, progressing thru the forms using this 'Next' Command Button seems
to work just fine.

I would like my data entry people to receive a notification when they are
trying to progress to the next form in the series if they are missing one of
these required fields. How can I make this happen?

Thank you.
 
K

Ken Snell [MVP]

You will to add code steps to your Next_Click subroutine that verifies that
all required controls have values entered:


Private Sub Next_Click()

On Error GoTo Err_Next_Click

If Len(Me.Control1.Value & "") = 0 Then
MsgBox "You must enter a value into this control."
Me.Control1.SetFocus
ElseIf Len(Me.Control2.Value & "") = 0 Then
MsgBox "You must enter a value into this control."
Me.Control2.SetFocus
ElseIf Len(Me.Control3.Value & "") = 0 Then
MsgBox "You must enter a value into this control."
Me.Control3.SetFocus
Else
Call OpenNextForm(Me.Name)
End If

Exit_Next_Click:
Exit Sub

Err_Next_Click:
DoCmd.Close acForm, Me.Name
Resume Exit_Next_Click

End Sub
 
G

Guest

Thanks again, Ken. Worked like a charm!

Ken Snell said:
You will to add code steps to your Next_Click subroutine that verifies that
all required controls have values entered:


Private Sub Next_Click()

On Error GoTo Err_Next_Click

If Len(Me.Control1.Value & "") = 0 Then
MsgBox "You must enter a value into this control."
Me.Control1.SetFocus
ElseIf Len(Me.Control2.Value & "") = 0 Then
MsgBox "You must enter a value into this control."
Me.Control2.SetFocus
ElseIf Len(Me.Control3.Value & "") = 0 Then
MsgBox "You must enter a value into this control."
Me.Control3.SetFocus
Else
Call OpenNextForm(Me.Name)
End If

Exit_Next_Click:
Exit Sub

Err_Next_Click:
DoCmd.Close acForm, Me.Name
Resume Exit_Next_Click

End Sub


--

Ken Snell
<MS ACCESS MVP>


Pat Dools said:
Hello,

I have a series of forms in a database that I progress thru by clicking on
a
'Next' Command Button present on the form that opens up the next form in
the
series based the 'id' field in the 'initial' form ('fScrEligCriteria') in
the
series (see code below):

Private Sub Next_Click()

On Error GoTo Err_Next_Click

Call OpenNextForm(Me.Name)

Exit_Next_Click:
Exit Sub

Err_Next_Click:
DoCmd.Close acForm, Me.Name
Resume Exit_Next_Click

End Sub

Sub OpenNextForm(strName As String)
Dim intOrder As Integer, frmName As String

On Error GoTo OpenNextForm_Err

intOrder = DLookup("[FormOrder]", "LU_Forms", "[FormName]= '" &
strName
& "'")
frmName = DLookup("[FormName]", "LU_Forms", "[FormOrder]= " & intOrder
+ 1)
If Not IsNull(frmName) Then
DoCmd.OpenForm frmName, , , "[id] = Forms.fScrEligCriteria.id"
'DoCmd.OpenForm frmName, , , , acAdd
End If
DoCmd.Close acForm, strName

OpenNextForm_Err:
'MsgBox Err.Description
Resume Next

End Sub

It works great, but the thing is that if a required field is not filled
out,
hitting next still allows the user to progress to the next form and does
not
alert the data entry person that a required field has not been filled out.
It does not save the record in the underlying table (which is good). I
un-commented out the error section of the code in the OpenNextForm sub:

OpenNextForm_Err:
'MsgBox Err.Description
Resume Next

but, all is says is 'Object doesn't support this property or method'--
which
I'm not sure why this error message comes up, since data entry into this
database, progressing thru the forms using this 'Next' Command Button
seems
to work just fine.

I would like my data entry people to receive a notification when they are
trying to progress to the next form in the series if they are missing one
of
these required fields. How can I make this happen?

Thank you.
 

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