Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple format question about msgbox 2

Status
Not open for further replies.

cfvcf

Technical User
Nov 8, 2007
77
US
I want to format a message box so that it has separate lines and doesn't just run together. I know this has got to be simple...
below is my msgbox:
MsgBox "This is either an existing bank or you did not enter (at a minimum)" & _
"the Organization Name and the Name Abbreviation before adding accounts. " & _
"org name = " & Me.txt_OrgName & _
"org name abrev = " & Me.txt_OrgNameAbrev & _
"Error = " & Error$

Also, where can I find a list of errors so that I can make a msgbox unique to the specific problem?

Thanks!
 
Concatenate vbCrLf at the end of each line (carriage return/linefeed). I had code to enumerate all the error numbers and descriptions in the error object into a table, but can't find it right now. If I find it, I'll post back....

Money can't buy happiness -- but somehow it's more comfortable to cry in a Corvette than in a Yugo.
 
Duh! Probably all you want is err.number and err.description. Just concatenate at the end of the string (like & Err.Number & vbCrLf & Err.Description).

Money can't buy happiness -- but somehow it's more comfortable to cry in a Corvette than in a Yugo.
 
OK, found the other code. Unfortunately I can't remember the original author; I tweaked it a bit as well:
Code:
Sub CreateErrorsTable()

'The following procedure creates a table in Microsoft Access containing the error codes
'and strings used or reserved by Visual Basic. The table doesn't include Data Access
'Objects (DAO) errors.
'Visual Basic reserves a portion of the first thousand possible error numbers, so this
'example considers only error numbers between 1 and 1000. Other error numbers are
'reserved by the Microsoft Jet database engine, or are available for defining custom errors.

    Dim dbs As Database, tdf As TableDef, fld As Field
    Dim rst As Recordset, lngCode As Long
    Const conAppObjectError = "Application-defined or object-defined error"

    ' Create Errors table with ErrorNumber and ErrorDescription fields.
    Set dbs = CurrentDb
    Set tdf = dbs.CreateTableDef("Errors")
    Set fld = tdf.CreateField("ErrorCode", dbLong)
    tdf.Fields.Append fld
    Set fld = tdf.CreateField("ErrorString", dbText, 255)
    tdf.Fields.Append fld
    dbs.TableDefs.Append tdf
    Set rst = dbs.OpenRecordset("Errors")
    For lngCode = 1 To 1000  ' Loop through first 1000 Visual Basic error codes.
        On Error Resume Next
        Err.Raise lngCode   'Raise each error.
        DoCmd.Hourglass True
        ' Skip error codes that generate application or object-defined errors.
        If Err.Description <> conAppObjectError Then
            rst.AddNew
            rst!ErrorCode = Err.Number
            rst!ErrorString = Err.Description
            rst.Update
        End If
        Err.Clear
    Next lngCode
    rst.Close
    DoCmd.Hourglass False
    MsgBox "Errors table created."
    Set rst = Nothing
    Set dbs = Nothing
    
End Sub

Money can't buy happiness -- but somehow it's more comfortable to cry in a Corvette than in a Yugo.
 
Wow, I'll have to look at this in the morning - thanks so much for putting so much effort in this!
 

I try to credit the author whenever I post something like this that's taken some time to develop, but you're not short changing anyone here,genomon! That code came from Billy Bob Gates' boys at Micro$oft! It's listed in the Knowledge Base at KB268721.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
I'd replace this:
For lngCode = 1 To 1000 ' Loop through first 1000 Visual Basic error codes.
On Error Resume Next
Err.Raise lngCode 'Raise each error.
DoCmd.Hourglass True
' Skip error codes that generate application or object-defined errors.
If Err.Description <> conAppObjectError Then
rst.AddNew
rst!ErrorCode = Err.Number
rst!ErrorString = Err.Description
rst.Update
End If
Err.Clear
Next lngCode
with this:
Code:
With rst
  For lngCode = 0 To 32767
    If Trim(AccessError(lngCode) & "") <> conAppObjectError _
    And Trim(AccessError(lngCode) & "") <> "" Then
      .AddNew
      !ErrorCode = lngCode
      !ErrorString = AccessError(lngCode)
      .Update
    ElseIf Trim(Error(lngCode) & "") <> conAppObjectError _
    And Trim(Error(lngCode) & "") <> "" Then
      .AddNew
      !ErrorCode = lngCode
      !ErrorString = Error(lngCode)
      .Update
    End If
  Next
End With

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Sorry I'm late at getting back to this, been working on other issues. But about the multi-line msgbox, what do you mean by "Concatenate vbCrLf at the end of each line (carriage return/linefeed)".
Do you have an example? Thanks!
 
Sample code:
Code:
PRINT_REPORTS_EXIT:
    Exit Sub
  
PRINT_REPORTS_ERR:
    MsgBox "Print Reports " & vbCrLf & "Error Number: " & Err.Number _
           & vbCrLf & Err.Description, vbCritical
    Resume PRINT_REPORTS_EXIT

This is a really really basic skill (string manipulation) and is covered well in the Access help documentation.

Alcohol and calculus don't mix, so don't drink and derive.
 
Thanks, I hope the alcohol quote wasn't meant for me, I don't drink. Thanks again.
 
in order to put multi lines in a message box use the following

MsgBox "First line text" & chr(13) & "Second Line Text " & chr(13) & "Third Line Text"

This will place a "return" which is Chr(13). THen you can change the line values to whatever you want combining the err numbers and messages as shown in the previous posts


.....
I'd rather be surfing
 
chr(13) is vbCr (carriage return). Can't remember what vbLf (line feed) evaluates to.
vbCrLf is a combination of both (and easier to remember as well as intuitive).

Computers make very fast, very accurate mistakes.
 
thanks genonmon

i did not know about vbCrLf


.....
I'd rather be surfing
 
There's also the infamous constant [blue]vbNewLine[/blue]:
Code:
[blue]   Dim NL As String
   
   NL = vbNewLine
   
   MsgBox "This is a seperate line" & NL & _
          "This is another!"[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top