Results 1 to 14 of 14
  1. #1
    BLFOSTER is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2013
    Posts
    68

    Use function in message box?

    Is it possible to use a function within a message box? I want to show our current version number. For Example: MsgBox "Blah Blah Blah", vbOKOnly, "STracking fGetVerNo".

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Sure. It would just be something like:
    Code:
    MsgBox "Blah Blah Blah", vbOKOnly, "STracking " & GetVerNo
    assuming that your function does not need any parameters and can run like that normally.

  3. #3
    BLFOSTER is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2013
    Posts
    68
    Oh thank you. I am still doing something wrong. What I get is STracking & getVerNo. Just don't know the proper syntax I guess

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    JoeM has shown correct syntax. Note that the function call is not within quotes - it is concatenated. What are you doing different? Post your attempted syntax.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    BLFOSTER is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2013
    Posts
    68
    Ok. So I moved the Quotation marks, and now what I get is JUST STracking - nothing else. Maybe it is the function....?

    MsgBox "Blah Blah Blah", vbOKOnly, "STracking " & getVerNo

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Maybe JoeM didn't get your function name correct. Is it fGetVerNo?

    If still not working, post the code from the function.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    BLFOSTER is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2013
    Posts
    68
    Well, it's actually called getClientID() and that is what I used in my code, just used getVerNo to avoid confusion. Here is the function:
    Public Function getClientID() As Integer
    On Error GoTo getClientIDError

    Dim db As Database
    Dim rs As Recordset
    Dim lID As Date

    Set db = OpenDatabase("c:\sts\STracking.accde")

    Set rs = db.OpenRecordset("tblInfo")

    With rs
    .MoveLast
    getClientID = .Fields("ID")
    End With

    rs.Close
    db.Close
    Exit Function

    getClientIDError:
    getClientID = 0

    End Function

  8. #8
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Maybe JoeM didn't get your function name correct. Is it fGetVerNo?
    Oops. Typo on my part. That "f" should be there.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    To me, getVerNo means something entirely different than getClientID.

    What makes you certain that the last record of unfiltered and unsorted recordset has the value you want? Is there only 1 record in the table?

    To retrieve just a single value I would prefer a DLookup instead of opening recordset.

    Another alternative is when database opens to set value of textbox on a form that never closes, such as a Main Menu. I do this. Then the value is always available for reference.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Dim intID as integer

    IntID = GetClientID

    Msgbox intid

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    ItsMe, setting to variable is not necessary. MsgBox calling function should work. Something else must be wrong.

    Joe, have you step debugged?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Interesting, never tried it.

  13. #13
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Joe, have you step debugged?
    I think you meant this question for the OP, not me, right?

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Yep, sorry picked up wrong name. So, BLFOSTER, have you step debugged? I can't see anything wrong with the code.

    On second thought, a DMax() might be preferred domain aggregate function.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 8
    Last Post: 01-31-2014, 01:45 PM
  2. Replies: 2
    Last Post: 01-23-2014, 12:40 PM
  3. Replies: 15
    Last Post: 11-01-2013, 03:24 PM
  4. Replies: 9
    Last Post: 09-26-2012, 12:20 PM
  5. an aggregate function error message
    By newtoAccess in forum Queries
    Replies: 1
    Last Post: 11-27-2010, 05:18 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