Results 1 to 6 of 6

Thread: [RESOLVED] Help: What is the easiest way to have Error write to an error log.txt

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    71

    Resolved [RESOLVED] Help: What is the easiest way to have Error write to an error log.txt

    Hi ALL

    I am a beginner in this..
    I found the easiest to trap an error is just create a message box

    ErrTrap:
    MsgBox "Error trying to update the current record: " & Err.Description, vbCritical + vbOKOnly, App.Title

    Now I want it to write this error to a file also ..
    Could some one help me create a simple function that will write the message to an error.txt

    it could be as primitive and simple ..

    please help

    thank you

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Help: What is the easiest way to have Error write to an error log.txt

    Quote Originally Posted by ndondo
    Hi ALL

    I am a beginner in this..
    I found the easiest to trap an error is just create a message box

    ErrTrap:
    MsgBox "Error trying to update the current record: " & Err.Description, vbCritical + vbOKOnly, App.Title

    Now I want it to write this error to a file also ..
    Could some one help me create a simple function that will write the message to an error.txt

    it could be as primitive and simple ..

    please help

    thank you
    Declare a string variable and store the above message to that
    If you search the forum, you will see plenty of example on how to write to a text file. simply write the variable's data to text...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Help: What is the easiest way to have Error write to an error log.txt

    Code:
    Private Sub Command1_Click()
    On Error GoTo ErrTrap
    
    'way cool code
    Exit Sub
    ErrTrap:
    Open "c:\errorlog.txt" For Append As #1
    Print #1, "An Error has occurred on " & Format(Now, "mm/dd/yyyy") & " in Command1_Click" & vbCrLf & vbCrLf
    Print #1, "The error is: " & Err.Number & " " & Err.Description
    Close #1
    End Sub

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    71

    Re: Help: What is the easiest way to have Error write to an error log.txt

    Thank you!
    I will try it and post back!

    I appreciate it very much

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Help: What is the easiest way to have Error write to an error log.txt

    You can add pretty much anything you want.

    I write my errors back to an errorlog DB table which includes the username, machine name, date/time of the error, where in the program the error occured and what the error number and error description is.

    I built a special Admin Only screen which will display all errors in the table, and when you click on one, it will give the details as logged. In addition, the table also includes a field for notes and resolutions so that anytime anyone with permissions to the errorslog table (like my boss ) can go in a take a look at what has been going on, and what has been done about it.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    71

    Resolved Re: Help: What is the easiest way to have Error write to an error log.txt

    This Solved my Problem!

    Thank you very much sir

Posting Permissions

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



Click Here to Expand Forum to Full Width