Results 1 to 7 of 7
  1. #1
    Fiddler is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2018
    Posts
    15

    msgbox not working

    This is embarrassing and sorry for the long post. I've worked with MS Access since the mid 1990s and have literally created hundreds of programs. One thing I use to help debug code is quick and easy msgboxes, plus I use them behind forms for various things. I quit programming in 2009 and just recently went back into it with Office 365. I've found out that my quick and easy tool no longer works in this version, and works more like an input box than a msgbox. Am I right? Did it change? Have I failed to set some reference?

    It used to be (down and dirty): msgbox="What a beautiful day" & OptionalParm, vbOkayonly, "MyTitle"


    OR msgbox("What a beautiful day", vbOkayonly, "MyTitle")
    OR (for debugging) msgbox "Code failed here"

    but now I'm *required* to declare a variant and set it up this way:
    dim msgTxt
    msgtxt=msgbox("My cumbersome message")

    If I don't set it up this way I get an error message stating that the right hand value must return a function call. This is more like an input box than a message box (of old).

    Of course, the VBOkayOnly was selected from the intellisense dropdown

    I find I cannot put the "vbOkayOnly" or any other thing after the initial message--it actually fails on the comma. Normally, I don't need to capture the return value of the vbOkayOnly, and I'm wondering if I'm just so rusty I've forgotten how to create a simple msgbox, or if it has changed someway. It's annoying not to be able to create a title without it failing or to do a simple box for code debugging.

    Thanks for any help.

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    Msgbox("Hello World") -this format is a function
    Msgbox "Hello World" is what you want.

  3. #3
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    You need some rust remover.

    MsgBox hasn't changed but the button code is VbOKOnly.
    Having said that, there is absolutely no point including that as it is the default setting

    Remove the brackets unless you are using it to check user response to e.g. VbYesNo button

    Code:
    if MsgBox ("some text", vbYesNo+vbQuestion,"title text")=vbYes then
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  4. #4
    Fiddler is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2018
    Posts
    15
    Thanks--I could swear I've done it both ways, but I'll check again today at work.

  5. #5
    Fiddler is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2018
    Posts
    15
    Yeah, you're right about the button code. Amazing what you forget when going from memory without intellisense. I seldom use a msgbox this way, but thanks for the reminder as you're right! The rust is cracking off slowly... Time for WD40... Thanks.

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    LOL
    I read this
    Amazing what you forget when going from memory without intellisense.
    as
    Amazing what you forget when going from memory without intelligence.
    which applies to me far too often
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Regardless of how you use it, Msgbox is a function. The parentheses must not be used unless the Msgbox result is being used, such as when it's assigned to a variable. If the function isn't returning a value, then an error will be raised if parentheses are used.
    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. Can't Remove MsgBox without module not working
    By cm-net in forum Programming
    Replies: 1
    Last Post: 01-20-2018, 07:49 AM
  2. vba MsgBox for some but not all
    By BusDriver3 in forum Macros
    Replies: 18
    Last Post: 12-15-2016, 09:33 PM
  3. Yes No msgbox
    By imintrouble in forum Access
    Replies: 3
    Last Post: 10-14-2011, 02:24 PM
  4. MsgBox
    By Mtyetti in forum Forms
    Replies: 4
    Last Post: 07-27-2011, 01:51 PM
  5. Msgbox And Search Code Not Working Properly
    By vampyr07au in forum Forms
    Replies: 1
    Last Post: 05-02-2011, 05:16 PM

Tags for this Thread

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