Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Dec 2000
    Location
    USA
    Posts
    379
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Why is this Procedure executed 3 times? (Access97 SR-2)

    The switchboard executes a macro which runs the function RunFixSONO.The function RunFixSONO calls the procedure FixSONO, and everything works properly except that the procedure is called 3 times. I placed the MsgBox statements in the procedure code to tell me when I am entering and leaving the procedure and I see it happen 3 times. I am incredulous ... can someone please tell me what is happening here? Why is the procedure running exactly 3 times, every time, when I only call it once?

    Function RunFixSONO()
    FixSONO
    End Function

    Sub FixSONO()

    Dim db As Database
    Dim rsDaily As Recordset
    Dim vCountProcessed As Integer
    Dim vmsg As String
    Dim vErrorFlag As Integer
    Dim vSONO As String


    vmsg = "entering Procedure"
    MsgBox (vmsg)
    vCountProcessed = 0
    vErrorFlag = 0
    Set db = CurrentDb
    Set rsDaily = db.OpenRecordset("DAILY", dbOpenDynaset)
    Do While rsDaily.EOF = False And vErrorFlag = 0
    With rsDaily
    'If SONO length = 8
    If Len(rsDaily!SONO) = 8 Then
    rsDaily.Edit
    rsDaily!SONO = Mid(rsDaily!SONO, 4, 7)
    .Update
    vCountProcessed = vCountProcessed + 1
    Else
    vErrorFlag = 1
    End If
    .MoveNext
    End With
    Loop
    If vErrorFlag = 1 Then
    vmsg = "Incorrect SONO Length encountered; Notify Management"
    MsgBox (vmsg)
    vmsg = vCountProcessed & " SONO records were processed before the error"
    MsgBox (vmsg)
    Else
    vmsg = vCountProcessed & " SONO records were processed"
    MsgBox (vmsg)
    End If
    DoCmd.OpenQuery "qryAppend SBT data"
    'Close open objects
    rsDaily.Close
    db.Close
    vmsg = "leaving Procedure"
    MsgBox (vmsg)

    End Sub

    Sorry about losing the indents. I don't know how to keep them when I paste the code in.
    Thank you in advance to anyone who can take a look at this and give me a clue.

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Why is this Procedure executed 3 times? (Access97 SR-2)

    You keep the indents by use the [ pre] tags from the tag panel.

    Are you saying that the procedure FixSONO is run 3 times? Always 3 or does it vary? Why are you executing a macro to run a code routine? You should be able to run function directly from your switchboard. If you do that, does it still run 3 times?
    Charlotte

  3. #3
    3 Star Lounger
    Join Date
    Dec 2000
    Location
    USA
    Posts
    379
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Why is this Procedure executed 3 times? (Access97 SR-2)

    I can't find a tag panel ...where might that be?

    It always ran 3 times, never varied. I finally realized that I needed to call the function with () after the function name and had not included the (). As soon as I put them in, it ran only once as expected. Why that would cause the procedure to run 3 times, I cannot imagine.

    I wish I could figure out how to merely call the function from the switchboard with RunCode. I do not understand where to put the Function and the Procedure. Do they belong in the module window (separately as one Function and one Procedure or together?) or behind the Switchboard form? If you could help me understand this part, it would certainly get rid of these hoops I have been jumping through.

    You consistently help me through my difficulties and I am very grateful.

  4. #4
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Emerald Beach, New South Wales, Australia
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Why is this Procedure executed 3 times? (Access97 SR-2)

    If it is the access generated switchboard the button click will call something like "=HandleButtonClick(1)"

    This gets the menu, the command type and the argument. The handlebuttonclick () uses the following, check yours to make sure it is the same,

    Const conCmdGotoSwitchboard = 1
    Const conCmdOpenFormAdd = 2
    Const conCmdOpenFormBrowse = 3
    Const conCmdOpenReport = 4
    Const conCmdCustomizeSwitchboard = 5
    Const conCmdExitApplication = 6
    Const conCmdRunMacro = 7
    Const conCmdRunCode = 8

    in this case to run the code just replace the 7 with 8 in tblSwitchboardItems and change the argument from the macro name to the function name.

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Why is this Procedure executed 3 times? (Access97 SR-2)

    Look just above the text area when you make a post. You'll see 1-Click TagPanel and Smilies links there. If you click on the TagPanel, you'll see tags you can click on to enter at the end of whatever text you've already typed. Just paste your code over the "text" between the beginning and ending tags ([ pre] and [ /pre]). Alternatively, you can just type them in yourself, but take out the extra spaces I stuck in so they would remain visible in the message.

    Stewart answered your other question in his post.
    Charlotte

  6. #6
    3 Star Lounger
    Join Date
    Dec 2000
    Location
    USA
    Posts
    379
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Thanks, it's working (Access97 SR-2)

    Found the tag panel ... it is precisely where you said (perfectly obvious, I'm embarrassed to say).

    Thanks to both of you - I have the code running now from the switchboard. (I had the code behind the switchboard and apparently it belongs in the module tab).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •