question about command button

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I know this should be easy, but.....

I have a command button that when clicked displays information about a
particular patron.
here is a copy of the code that I'm using right now:
---
Private Sub View_Add_Incidents_Click()
On Error GoTo Err_View_Add_Incidents_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmIncident"

stLinkCriteria = "[PatronID]=" & Me![PatronID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_View_Add_Incidents_Click:
Exit Sub

Err_View_Add_Incidents_Click:
MsgBox Err.Description
Resume Exit_View_Add_Incidents_Click

End Sub
---
I would like to be able to display a message if there is no information for
that patron. Any help would be appreciated.

Thanks,
Mark
 
Couple of ways to do it....here's one:

Private Sub View_Add_Incidents_Click()
On Error GoTo Err_View_Add_Incidents_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmIncident"

stLinkCriteria = "[PatronID]=" & Me![PatronID]
DoCmd.OpenForm stDocName, , , stLinkCriteria, , acHidden
If Forms(strDocName).Recordset.RecordCount = 0 Then
MsgBox "There are no records to display."
DoCmd.Close acForm, strDocName
Else
Forms(strDocName).Visible = True
End If

Exit_View_Add_Incidents_Click:
Exit Sub

Err_View_Add_Incidents_Click:
MsgBox Err.Description
Resume Exit_View_Add_Incidents_Click

End Sub
 
Hi Ken,

Thanks for the reply, but after I inserted the revised code, it would not
display the error message, nor would it open the form even if the patron had
records.

Thanks,
Mark
Ken Snell said:
Couple of ways to do it....here's one:

Private Sub View_Add_Incidents_Click()
On Error GoTo Err_View_Add_Incidents_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmIncident"

stLinkCriteria = "[PatronID]=" & Me![PatronID]
DoCmd.OpenForm stDocName, , , stLinkCriteria, , acHidden
If Forms(strDocName).Recordset.RecordCount = 0 Then
MsgBox "There are no records to display."
DoCmd.Close acForm, strDocName
Else
Forms(strDocName).Visible = True
End If

Exit_View_Add_Incidents_Click:
Exit Sub

Err_View_Add_Incidents_Click:
MsgBox Err.Description
Resume Exit_View_Add_Incidents_Click

End Sub

--
Ken Snell
<MS ACCESS MVP>

Mark said:
I know this should be easy, but.....

I have a command button that when clicked displays information about a
particular patron.
here is a copy of the code that I'm using right now:
---
Private Sub View_Add_Incidents_Click()
On Error GoTo Err_View_Add_Incidents_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmIncident"

stLinkCriteria = "[PatronID]=" & Me![PatronID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_View_Add_Incidents_Click:
Exit Sub

Err_View_Add_Incidents_Click:
MsgBox Err.Description
Resume Exit_View_Add_Incidents_Click

End Sub
---
I would like to be able to display a message if there is no information for
that patron. Any help would be appreciated.

Thanks,
Mark
 
One or the other should occur from the code example that I posted. I have
even tested it on a sample setup database.

You may have other things going on. Please post the entire code that this is
a part of.


--
Ken Snell
<MS ACCESS MVP>

Mark said:
Hi Ken,

Thanks for the reply, but after I inserted the revised code, it would not
display the error message, nor would it open the form even if the patron had
records.

Thanks,
Mark
Ken Snell said:
Couple of ways to do it....here's one:

Private Sub View_Add_Incidents_Click()
On Error GoTo Err_View_Add_Incidents_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmIncident"

stLinkCriteria = "[PatronID]=" & Me![PatronID]
DoCmd.OpenForm stDocName, , , stLinkCriteria, , acHidden
If Forms(strDocName).Recordset.RecordCount = 0 Then
MsgBox "There are no records to display."
DoCmd.Close acForm, strDocName
Else
Forms(strDocName).Visible = True
End If

Exit_View_Add_Incidents_Click:
Exit Sub

Err_View_Add_Incidents_Click:
MsgBox Err.Description
Resume Exit_View_Add_Incidents_Click

End Sub

--
Ken Snell
<MS ACCESS MVP>

Mark said:
I know this should be easy, but.....

I have a command button that when clicked displays information about a
particular patron.
here is a copy of the code that I'm using right now:
---
Private Sub View_Add_Incidents_Click()
On Error GoTo Err_View_Add_Incidents_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmIncident"

stLinkCriteria = "[PatronID]=" & Me![PatronID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_View_Add_Incidents_Click:
Exit Sub

Err_View_Add_Incidents_Click:
MsgBox Err.Description
Resume Exit_View_Add_Incidents_Click

End Sub
information
for
that patron. Any help would be appreciated.

Thanks,
Mark
 
Back
Top