Delete Query Messages

Howlsta

Vampire Slayer
Local time
Today, 22:23
Joined
Jul 18, 2001
Messages
180
The code below runs a delete query which works fine, but sometimes a user might press the command button and the delete query has no records. What i'm really saying is how can I give the user a error/help message if they press the button and there are no records to delete.
I turned off the warning as they are still the same anyway whether there are records to delete or not.
Any Ideas?

Private Sub cmdWithdraw_Click()

On Error GoTo Err_cmdWithdraw_Click

Dim stQry As String

stQry = "qDelOption"
DoCmd.SetWarnings False
DoCmd.OpenQuery stQry, acNormal, acEdit
DoCmd.SetWarnings True
Me.lboOptions.Requery
Exit_cmdWithdraw_Click:
Exit Sub

Err_cmdWithdraw_Click:
MsgBox Err.Description
Resume Exit_cmdWithdraw_Click
End Sub
 
If I understand you correctly you could probably use a DCount. The syntax is the same as a Dlookup and I use them to check for job numbers in a table before I open reports based on the job number. This is an example:

Dim strMsg As String, strTitle As String
Dim intStyle As Integer, cancel As Integer
Dim Answer As Variant
Dim strInput As String

strInput = InputBox("Enter job number", "Select Job")
If strInput = "" Then Exit Sub

If DCount("[JobNumber]", "TimeGR", "[JobNumber]= '" & strInput & "'") = 0 Then
strMsg = "Please try a different number"
strTitle = "Report Not Found"
intStyle = vbOKCancel + vbInformation
Answer = MsgBox(strMsg, intStyle, strTitle)
If Answer = vbCancel Then cancel = True
Exit Sub

If the Dcount returns a 0 the message is displayed. Otherwise the rest of the code (not shown here) is carried out.
 

Users who are viewing this thread

Back
Top Bottom