Results 1 to 9 of 9
  1. #1
    2 Star Lounger
    Join Date
    Mar 2004
    Location
    Christchurch
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Field text in msgbox (2002)

    Hi, I have a sub-form that users enter data into, and on them completing a record and moving to a new record I want to display a message box prompt with some text and the value of a field on that record. I can get the message box to appear via the AfterUpdate event via:
    msgbox "hello world",vbOKOnly,"Title for message box"

    How would I add to "hello world", referencing the text of a field on that sub-form?

    Cheers, Roger

  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Field text in msgbox (2002)

    Dim strmessage as string
    Dim strTitle as string

    strmessage ="Hello World " & me.[somefieldname] & " and " & me.[someotherfield]
    strTitle = "My different title."

    msgbox strmessage, vbOKOnly, strTitle

    This assumes that this code runs from the subform itself. If it were run from the main form, you would need to replace me with a more complex expression.
    Regards
    John



  3. #3
    2 Star Lounger
    Join Date
    Mar 2004
    Location
    Christchurch
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Field text in msgbox (2002)

    Nice, thank you very much, just what I needed.
    Roger

  4. #4
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Moundridge, Kansas, USA
    Posts
    342
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Field text in msgbox (2002)

    I would like to add to woja's question. I have a subform that I enter Order Details in, and have code that looks up if the current product is on backorder and if so, a msgbox pops up. Now, the way the cboProductID is set up is (ProductID 'text format', ProductName 'text format', Discontinued 'yes/no' and Pages 'number format'). I can get it to show the ProductID with this code If DLookup("Backordered", "tblProducts", "ProductID='" & Me.Parent!sbfPrisonOrderDetails!ProductID & "'") = True Then
    MsgBox "This item " & Me.cboProductID & " is on backorder!", , "Information!" End If
    , but what I want it to show is ProductName. Currently it just shows the ProductID which is a unique, decipherable code, but not user friendly. How can I have it show just the ProductName that is currently on backorder?

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

    Re: Field text in msgbox (2002)

    Change the line

    MsgBox "This item " & Me.cboProductID & " is on backorder!", , "Information!"

    to

    MsgBox "This item " & Me.cboProductID.Column(1) & " is on backorder!", , "Information!"

    Column is zero-based, so Column(1) is the 2nd column of the combo box.

  6. #6
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Moundridge, Kansas, USA
    Posts
    342
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Field text in msgbox (2002)

    That did it! Is there any way to add quotes to that so it looks like this This item 'Widget 1' is on backorder?

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

    Re: Field text in msgbox (2002)

    Yes, like this:
    <code>
    MsgBox "This item '" & Me.cboProductID.Column(1) & "' is on backorder!", , "Information!"
    </code>
    or if you prefer
    <code>
    MsgBox "This item " & Chr(39) & Me.cboProductID.Column(1) & Chr(39) & " is on backorder!", , "Information!"
    </code>
    Chr(39) is the single quote character '.

  8. #8
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Moundridge, Kansas, USA
    Posts
    342
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Field text in msgbox (2002)

    Many thanks!

    Vrolijk Kerstfeest en een Gelukkig Nieuwjaar

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

    Re: Field text in msgbox (2002)

    Thanks, and Merry Christmas and a Happy New Year to you!

Posting Permissions

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