Msg box"the record doesn't exist, do you want to create it?"

TheWanderer

New member
Local time
Today, 13:21
Joined
Feb 3, 2013
Messages
7
I have been searching the forum for an answer to my question, but so far haven't found it. I thought I'd just ask and hopefully someone can point me in the right direction?

I am using Access 2010.

I have a form which is basically just a text box search function. I want the user to be able to type in a document number and then a form to open displaying that record. This bit I can do. If a user types in a document number that doesn't exist then a blank form opens. What I would really like is that a message box opens saying "The document doesn't exist. Would you like to create it?" with the button Yes and No. If yes pressed, a blank form opens, if no the message box closes and nothing happens.

If you could tell me the code and where to put the code it would be much appreciated.
 
I used the wizard when I created the button on the menu form which when pressed opens the other form and displays the record that matches the text box in my menu form. It has used an embedded macro instead of and Event Procedure so I don't actually have any code!

(I have tried going into Options and checked the box that says Always use Event Procedures but it is still using macros in wizards!)
 
Without code I am at a loss.
Can you convert to 2003?

-----------------------------------------------

Other than that Google search "Not in List"
There you should be able to find some code.
 
Thank you very much for your help. After trying and failing to convert the database to 2003 and also using the convert macro button (which put an error in the code!) I did a google search on Not in List and have found some code which I think will really help me out.
 
I use the following code in one of my databases that does what you want, although I use Access 2003. Just paste it into the forms module.

Code:
Private Sub Form_Open(Cancel As Integer)
    Dim rs As DAO.Recordset
    Set rs = Me.Recordset
    If rs.RecordCount = 0 Then
        If MsgBox("This ID does not exist. Would you like to create it?", vbYesNo + vbQuestion, "No Record Exists") = vbYes Then
            DoCmd.GoToRecord , , acNewRec
        Else
            DoCmd.Close
        End If
    End If
    Set rs = Nothing
End Sub

Just alter the message text to suit your needs.
 

Users who are viewing this thread

Back
Top Bottom