Hi world,
From a search style form, clicking search button starts my query which opens my query results form. If there are no records found from the search I have some code that during the 'on open' event of results form, opens a yes no message box. - "No clients found, would you like to add a new client?"
Clicking Yes takes user to 'new client form'
Clicking No cancels the openform event and takes user back to search form.
This all works fine, but what also happens is there is a 2501 dialog message "An openform action has been cancelled" that also pops up as a result of clicking no and cancelling the form opening action.
How can I supress this, bearing in mind its not triggering from an error?
I have tried various methods and not got one working. Maybe because I did it wrong... Not sure.
Have tried adding a doCmd.SetWarnings (True/False/WarningsOn/WarningsOff)...
Have tried adding On Error Resume Next
Have also tried an error handler, similar to from here....
http://answers.microsoft.com/en-us/o...5-009e2ee88050
Here is my "On Open" code.....
Code:
Option Compare Database
Private Sub Form_Open(cancel As Integer)
Dim intAnswer As Integer
If Me.Recordset.RecordCount = 0 Then 'If there are no records found, open YesNo box -
Select Case MsgBox("Do you want to add a new Client?", vbQuestion + vbYesNo, "No clients found")
Case vbYes 'When users click yes....
Dim stDocName As String
stDocName = "FrmNewClient"
DoCmd.OpenForm "FrmNewClient" 'Open new client form
DoCmd.OpenForm stDocName, , , acFormAdd 'open as new record
DoCmd.Close acForm, Me.Name 'Close search form
Case vbNo 'when users click no....
cancel = True 'Stop trying to load the form
DoCmd.OpenForm "SearchF" 'Go back to search form
End Select
End If
End Sub
Any help would be splendid.
Jamie.