Results 1 to 9 of 9
  1. #1
    jamierbooth is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Nov 2013
    Location
    Bristol
    Posts
    12

    Msgbox "no" button no directing me to the correct form.

    Hello world... I'm relatively new to access, but understand a bit. I'm trying to create a customer management dbase for the local council I work for, to make 50 or so colleagues lifes easier since the council is apparently skint and can't afford to buy one - we've been asking for about 10 years.

    I have a form which I use to search for clients google-style when I hit a command button, (using surname etc), the query runs and produces the results in another form, and closes the original search form. If there are matching results, everything is fine, my query results form loads and the person appears. If there are no matching results, during the 'on open' event of the query results form I have a yes-no msgbox come up.



    Clicking the Yes button re-directs me to a different form to enter a new client and closes the query results form. This works fine.
    I'm trying to make the No button take the user back to the search window and ready to make another search, however when I click no it closes the query results form and just goes back to the dbase window with no open forms....

    Can anyone help me with this code please?

    Code:
    Option Compare Database
    Option Explicit 
    
    Private Sub Form_Open(Cancel As Integer)
        If Me.Recordset.RecordCount = 0 Then
            Select Case MsgBox("Do you want to add a new Client?", vbQuestion + vbYesNo, "NO CLIENTS FOUND")
                Case vbYes
                    DoCmd.OpenForm "FrmNewClient", , , acFormAdd
                    DoCmd.Close acForm, Me.Name
                Case vbNo
                    DoCmd.Close acForm, Me.Name
                    DoCmd.OpenForm "SearchF"
            End Select
         End If
    End Sub

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    I can't see much wrong with your code. I don't think it should matter but you could just try opening the search form before closing the current form.
    Code:
    Option Compare DatabaseOption Explicit 
    
    Private Sub Form_Open(Cancel As Integer)
        If Me.Recordset.RecordCount = 0 Then
            Select Case MsgBox("Do you want to add a new Client?", vbQuestion + vbYesNo, "NO CLIENTS FOUND")
                Case vbYes
                    DoCmd.OpenForm "FrmNewClient", , , acFormAdd
                    DoCmd.Close acForm, Me.Name
                Case vbNo
                                DoCmd.OpenForm "SearchF"
                    DoCmd.Close acForm, Me.Name
    
            End Select
         End If End Sub
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    jamierbooth is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Nov 2013
    Location
    Bristol
    Posts
    12
    Have tried that already, and once just again to doubly make sure. It still doesn't open the search form!!

    Cheers.

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Have you checked the spelling of the form to be opened. What happens if you replace the Select Case with an If/else
    Code:
        If Me.Recordset.RecordCount = 0 Then
            If MsgBox("Do you want to add a new Client?", vbQuestion + vbYesNo, "NO CLIENTS FOUND") = vbTes Then
              DoCmd.OpenForm "FrmNewClient", , , acFormAdd
              DoCmd.Close acForm, Me.Name
            Else
              Msgbox "No Selected"
              DoCmd.OpenForm "SearchF"
              DoCmd.Close acForm, Me.Name
    
            End If
    End If
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    jamierbooth is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Nov 2013
    Location
    Bristol
    Posts
    12
    The form name is definitely correct. That code kind of worked the same and even stopped working in the same place! A 2nd msgbox popped up saying "No Selected", but then the 'cmd.openform' didn't happen and the other form closed and we went back to dbase window again... ?

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Well I'm as sure as I can be, that the code OK. Sorry, but it has been my experience that when strange/unusual things happen in Access that is a sign of some corruption. I suggest that you search for ways to recover from that. You could start by making a back up and then do a Compact and Repair.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  7. #7
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Allen Browne has some suggestion at: http://allenbrowne.com/ser-47.html
    In particular, look at "Symptom: "An error occurred while loading Form_FormName"
    "
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  8. #8
    jamierbooth is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Nov 2013
    Location
    Bristol
    Posts
    12
    OK. I'm still pretty early in design, so I guess I'll just start from scratch. It gives me a chance to clean up some stuff I could have done better from the start anyway. Shouldn't take me long. Thanks guys.

  9. #9
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Make sure you turn off the Name AutoCorrect feature
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 30
    Last Post: 09-27-2013, 01:34 PM
  2. Replies: 0
    Last Post: 03-13-2013, 08:00 AM
  3. Replies: 11
    Last Post: 03-29-2012, 02:32 PM
  4. Replies: 0
    Last Post: 01-11-2012, 12:34 PM
  5. "Yes to All" button in MsgBox
    By TheChairman in forum Forms
    Replies: 2
    Last Post: 12-23-2011, 01:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums