Results 1 to 12 of 12
  1. #1
    dr223 is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2010
    Posts
    20

    Message Box

    Hi,

    I have the following message box which works fine for the 1 field only

    Code:
    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("QryCalcWSM")
    If Not rs.EOF Then
       MsgBox " Business Options Based on WSM Score " & rs.Fields(0)
                                                    
    End If
    Results (Message box appears like..)

    Business Options Based on WSM Score MPESA

    However, I have a list of businesses extracted on QryCalcWSM;

    MPESA
    SUZUKI


    SAFARI
    TELECOM

    Now, I want to display on the message box

    Business Options Based on WSM Score
    MPESA
    SUZUKI
    SAFARI
    TELECOM

    any help please!! Thank you

  2. #2
    SoftwareMatters is offline Access VBA Developers
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    274
    Something like this should do it:

    Code:
     
    Dim rs As DAO.Recordset, strMessage
    Set rs = CurrentDb.OpenRecordset("QryCalcWSM")
    If Not rs.EOF Then
     strMessage  = ""
     rs.movefirst
     do until rs.eof
      strMessage = strMessage & rs.Fields(0) & chr(13) & chr(10)
      rs.movenext
     loop
        MsgBox " Business Options Based on WSM Score " & strMessage 
                                                    
    End If

  3. #3
    dr223 is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2010
    Posts
    20
    Excellent..

    But still comes up as

    Business Options Based on WSM Score MPESA
    SUZUKI
    SAFARI
    TELECOM

    Can I justify the business names centre and get something like;

    Business Options Based on WSM Score
    MPESA
    SUZUKI
    SAFARI
    TELECOM

    Thnak you so much ...

  4. #4
    SoftwareMatters is offline Access VBA Developers
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    274
    Not sure about justification but this should solve the first issue:

    If Not rs.EOF Then
    strMessage = Chr(13) & chr(10)
    rs.movefirst

  5. #5
    dr223 is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2010
    Posts
    20
    Thanks Softwarematters - anyone can help with the centre justification

  6. #6
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    You want this:
    Code:
    Business Options Based on WSM Score 
    MPESA
    SUZUKI
    SAFARI
    TELECOM

    . . . to look like this:
    Code:
     
    Business Options Based on WSM Score 
                    MPESA
                    SUZUKI
                    SAFARI
                   TELECOM
    Is that what you mean by Center justify??

    Your example didn't make it clear to me . . .

  7. #7
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,730
    Centre of what? You have a string which is left justified by default and the values have a certain length. What exactly are you expecting?

    You can use Space(10) or vbTab etc to move the string, but only you know the context of your question.


    OK I see Robeen has the same concern.

  8. #8
    dr223 is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2010
    Posts
    20
    Yes Robeen - Exactly...

    How can I update the code to accomodate this?

  9. #9
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    If you wanted it 'perfectly' center-justified, it could be tricky but you could calculate the Length of your string [Len(String)] and then pad with spaces like Orange suggested - using the Space() function to add spaces in front of each string.

  10. #10
    dr223 is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2010
    Posts
    20
    where should I put the code? Can you please put a sample on the code then I will try to add spaces to try to make it look justified..

    Thank you so much

  11. #11
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    for example, instead of this:
    Code:
     
    strMessage = strMessage & rs.Fields(0) & chr(13) & chr(10)
    try this:
    Code:
     
    strMessage = strMessage & Space(10) & rs.Fields(0) & chr(13) & chr(10)
    This will start every new name after 10 spaces on the line - so it won't be prefectly center-justified.

  12. #12
    dr223 is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2010
    Posts
    20
    Thank you so much

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

Similar Threads

  1. Message Box
    By JayX in forum Access
    Replies: 6
    Last Post: 12-13-2011, 02:28 PM
  2. Help with message box
    By Cablenm in forum Access
    Replies: 9
    Last Post: 10-14-2011, 05:06 PM
  3. Message Box
    By BorisGomel in forum Programming
    Replies: 6
    Last Post: 04-25-2011, 02:16 PM
  4. Message Box
    By dunnmel4 in forum Programming
    Replies: 9
    Last Post: 04-12-2011, 10:44 PM
  5. message box help
    By shaz10010 in forum Forms
    Replies: 1
    Last Post: 04-17-2009, 09:11 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