Results 1 to 8 of 8
  1. #1
    ijo68 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Feb 2021
    Posts
    39

    What am I doing wrong here?

    I am using a form to run a criteria query (frmSelTerrDS) to display records on another form (frmTerrDataSheet). In the 'onload' event of that form (frmTerrDataSheet), I am running code to check if the recordcount is 0 and if so display a message. I am trying to prompt the user with another message box asking if the user would like to redisplay the criteria form to make another choice , if yes the frmSelTerrDS opens if no, both forms close.. I get the second msgbox but when I click Yes nothing happens ..What am I doing wrong. Any help would be greatly appreciated.. Thank you.... Code below.

    *Update: When I try a different form it opens just fine.. is it possible that because the code in "frmSelTerrDS" closes it AfterUpdate it will not reopen it?

    Private Sub Form_Load()
    On Error Resume Next
    If Me.RecordsetClone.RecordCount = 0 Then
    MsgBox "No Records Found."



    DoCmd.Close acForm, Me.Name

    If MsgBox("Would you like to display another Group?", vbYesNo) = vbYes Then

    DoCmd.OpenForm acNormal, "frmSelTerrDS"


    End If
    End If
    End Sub

  2. #2
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,421
    Comment out (or remove) the On Error Resume Next, and you may find that there is an error that you are not aware of, which might be easy to fix.

  3. #3
    ijo68 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Feb 2021
    Posts
    39
    I did .. no errors

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,421
    Ah, I see a problem - it should be

    Docmd.openform "frmSelTerrDS", acnormal

  5. #5
    ijo68 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Feb 2021
    Posts
    39
    thank you for your reply , I tried that ,, didn't work. It seems that because the form is closed by the AfterUpdate event .. it does not reopen.. since I tried another form and it opened using the same code...is there another way to reopen

  6. #6
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,421
    Quote Originally Posted by ijo68 View Post
    thank you for your reply , I tried that ,, didn't work. It seems that because the form is closed by the AfterUpdate event .. it does not reopen.. since I tried another form and it opened using the same code...is there another way to reopen
    You're providing more information, but not enough. What 'afterupdate event'? You hadn't mentioned that before. Instead of eking out information in successive postings, perhaps you could get it all out by posting the DB.

  7. #7
    ijo68 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Feb 2021
    Posts
    39
    the afterupdate event of frmSelTerrDS closes that form after the user makes the selection.. However I figured it out .. Thanks for your input.. here is the working code:

    Private Sub Form_Load()
    'On Error Resume Next


    If Me.RecordsetClone.RecordCount = 0 Then


    MsgBox "No Records Entered For This Group.", vbInformation, "Group Display"

    DoCmd.Close acForm, "frmTerrDataSheet"



    If MsgBox("Would you like to display another Group?", vbYesNo, "Group Display") = vbYes Then



    DoCmd.OpenForm acNormal, "frmSelTerrDS"


    Else: DoCmd.Close acForm, "frmSelTerrDS"


    End If
    Exit Sub
    End If


    DoCmd.Close acForm, "frmSelTerrDS"
    End Sub

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,818
    I can only imagine that works up to now because you haven't clicked No yet. The view parameter is still before the name parameter, which is backwards:
    DoCmd.OpenForm acNormal, "frmSelTerrDS"

    Why not just present one message box instead of forcing an unnecessary response?

    Code:
    Private Sub Form_Load()
    Dim result As Integer
    
    If Me.RecordsetClone.RecordCount = 0 Then
        Result = MsgBox ("No Records Found." & vbCrLf & vbCrLf & "Would you like to display another Group?")
        If Result = vbYes Then 
            DoCmd.OpenForm, "frmSelTerrDS", acNormal
        Else
            DoCmd.Close
            Exit Sub
        End If
    End If
    DoCmd.Close acForm, "frmSelTerrDS"
    
    End Sub
    Not sure I see the point/need for opening a form that is already open but I guess it works? The implication is that it's not open but your posts read like it is, so why wouldn't it become active when you just close the datasheet form (assuming it was the last form that was active). Usual approach would be to simply close the 2nd form then the 1st becomes active - or you hide #1, open #2 and if you close #2, make #1 visible again.

    Please use code tags (# on posting toolbar) with proper indentation. Makes it so much easier to read, no? Besides, it stops the forum from doing wonky things to your code.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. what's wrong with this one?
    By markpastoril in forum Access
    Replies: 7
    Last Post: 07-12-2019, 12:56 AM
  2. What I am doing wrong?
    By qwerty in forum Access
    Replies: 5
    Last Post: 11-07-2018, 08:35 PM
  3. what is wrong
    By Dinoshop in forum Access
    Replies: 1
    Last Post: 07-11-2014, 06:22 AM
  4. What's wrong!
    By khalid in forum Programming
    Replies: 15
    Last Post: 06-27-2011, 06:38 AM
  5. What is wrong with this IFF?
    By bburton in forum Reports
    Replies: 2
    Last Post: 03-16-2011, 10:42 AM

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