Results 1 to 12 of 12
  1. #1
    eugzl is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2021
    Posts
    68

    how to insert in MsgBox string value from TextBox or ComboBox

    Hi All.
    In my form I check duplicate value before save record.
    Code:
                If DCount("*", "tblBrands", "Brand ='" & !Brand & "'") > 0 Then
                    MsgBox "Brand already exist. Please enter a different Brand.", vbOKOnly
                    SetSaveClose Me, False
                    Exit Sub
    Is it possible to insert Brand value into message box. I tried like this:


    Code:
    MsgBox "Brand " & txtBrand.Text & " already exist. Please enter a different Brand."
    But error message:
    Click image for larger version. 

Name:	MsgBox_Error.png 
Views:	13 
Size:	5.5 KB 
ID:	46872
    How to fix the problem?
    Thanks.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    Do not use the Text property. As the error states, to access that property that control must have the focus.
    I would always use Me.txtBrand as well ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    eugzl is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2021
    Posts
    68
    Hi Welshgasman. Thanks for reply.
    Is it possible to make Me.txtBrand bold font or change color in MsgBox? If yes. How it to do?

    Thanks.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    Not that I am aware of. There is an enhanced msgbox, but I have never used it, so not sure what can be done with it? Surround the brand with * or Google for it.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    eugzl is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2021
    Posts
    68
    I found online function to change font in a message box:
    Code:
    Public Function TestBoldMsgBox()
     
        Dim MsgBold As String
        Dim MsgNormal As String
     
        MsgBold = "This is a Bold Message"
        MsgNormal = "This is a  Normal Message"
     
        Debug.Print Eval("MsgBox ('" & MsgBold & vbNewLine _
        & "@" & MsgNormal & "@@', " & vbOKOnly & ", 'Testing Bold')")
     
    End Function
    But cannot figure out how to implement it in my case. Please help.

    Thanks

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    where did you find it? it may not be appropriate for VBA

    you can always use the title parameter as an attention getter plus you have the option to display various images

    see this link about what you can do with a msgbox in access
    https://support.microsoft.com/en-us/...6-ba9f1749f4c0

  7. #7
    eugzl is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2021
    Posts
    68

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    Works for me?
    What are you confused with?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #9
    eugzl is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2021
    Posts
    68
    I'm new in VBA and don't know how implement this function in code that I display in first post. I will appreciate if you show how it to do.

    Thanks.

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    Use it just as shown in place of your msgbox code. Change parameters to suit.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  11. #11
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    have the function return a value

    Code:
    Public Function TestBoldMsgBox() As Integer
     
        Dim MsgBold As String
        Dim MsgNormal As String
     
        MsgBold = "This is a Bold Message"
        MsgNormal = "This is a  Normal Message"
     
        TestBoldMsgBox = Eval("MsgBox ('" & MsgBold & vbNewLine _
        & "@" & MsgNormal & "@@', " & vbYesNoCancel & ", 'Testing Bold')")
     
    End Function
    ? TestBoldMsgBox()
    6 --vbYes
    7--vbNo
    2--vbCancel

    so in your vba code you might have

    if TestBoldMsgBox() =vbyes then 'do something

    or

    Code:
    select case TestBoldMsgBox()
      case vbYes
      
      case vbNo
    
      case cvCancel
    
    End Select
    you might want to change the name of the function to something more relevant and include parameters for the different parts of the message

  12. #12
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    If you really want a custom message box, create your own using a dialog form.
    Youtube video How to Create Custom Message box in Microsoft Access?
    Kind of simplistic and the music irritated me, but demonstrates the idea.
    Could pass in a parameter for custom messages using OpenArgs....


    Also look at custom message box
    Read the 3rd message by Wayne Gillespie.


    And I found a really interesting site Improved, Enhanced Message Box Replacement for MS Access
    I haven't tried this or even downloaded it....yet.
    It states "This project provides a custom and enhanced message box replacement for the default MsgBox found in Access."

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

Similar Threads

  1. Replies: 5
    Last Post: 06-15-2018, 03:14 PM
  2. Replies: 2
    Last Post: 12-22-2015, 09:09 PM
  3. Replies: 2
    Last Post: 04-05-2015, 06:06 PM
  4. Insert Field Value into MsgBox Text
    By jtm013 in forum Modules
    Replies: 4
    Last Post: 11-19-2014, 03:03 PM
  5. Replies: 3
    Last Post: 04-14-2014, 05:50 AM

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