Results 1 to 7 of 7
  1. #1
    4 Star Lounger
    Join Date
    May 2002
    Location
    Roanoke, Virginia, USA
    Posts
    493
    Thanks
    0
    Thanked 0 Times in 0 Posts

    MsgBox function (A2K SR1)

    I have an event on a form which uses a select case. The event woks fine for the 14 cases for
    PayCodeIDs 1, 2, 3 and 4. The selects case is based on RoomType ID and PayCode IDs. For
    example when RoomTypeID= Standard, then
    If PayCodeID =1 then a value is set
    If PayCodeID =2 then another value is set
    etc

    What I want to be able to do in some cases is that If PayCodeID = 5, I want to print a Message
    Box

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

    Re: MsgBox function (A2K SR1)

    I suspect that the error you're getting is because you are working with the control name but there is no form specified. Instead, pass the control as an object to the function like this:

    Function BusinessErrorMsg(<font color=blue>ctl As Control</font color=blue>)
    Dim strMsg As String

    strMsg = "Business Pay Period should only be used with Standard or Handicap rooms."
    MsgBox (strMsg)
    DoCmd.GoToControl ctl.Name
    End Function

    And call it like this from the form:

    If PayCodeID = 5 then BusinessErrorMsg(<font color=blue>Me.PayCodeID</font color=blue>)

    If that doesn't cure it for you, post the exact error message you're getting, including the explanation of the syntax error.
    Charlotte

  3. #3
    4 Star Lounger
    Join Date
    May 2002
    Location
    Roanoke, Virginia, USA
    Posts
    493
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MsgBox function (A2K SR1)

    The suggested changes did not work.

    In order to isolate on the problem, I eliminated the GoTOControl part of the function. I changed the function to:

    Function BusinessErrorMsg()
    Dim strMsg As String
    strMsg = "Business Pay Period should only be used with Standard or Handicap rooms."
    MsgBox (strMsg)
    End Function

    The AfterUpdate event works find until the following line of code is added:
    If PayCodeID = 5 Then BusinessErrorMsg()

    Set forth below is the Case 3 where I added the offending line of code. When the line is added, I get

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: MsgBox function (A2K SR1)

    Just a wild guess: use MsgBox strMsg instead of MsgBox (strMsg), and call it as BusinessErrorMsg instead of BusinessErrorMsg().

  5. #5
    4 Star Lounger
    Join Date
    May 2002
    Location
    Roanoke, Virginia, USA
    Posts
    493
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MsgBox function (A2K SR1)

    As usual your "Wild Guess" was right on target. Many Thanks.

    Tom

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

    Re: MsgBox function (A2K SR1)

    If you want the reasons, calling the function as you did, with the parens, is a syntax that you use to assign the result to the other side of an expression. Since you hadn't provided that expression (i.e., varValue = BusinessErrorMsg()), you got an error.
    Charlotte

  7. #7
    4 Star Lounger
    Join Date
    May 2002
    Location
    Roanoke, Virginia, USA
    Posts
    493
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MsgBox function (A2K SR1)

    Many thanks for the reason why. It should be beneficial in the future.

    Tom

Posting Permissions

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