Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Error Handling
I would like some general advice on error handling please.
In my code below once a user has filed out some values on a form the system tests for a multiuser workbook being open. Only when it gets the book as read write will it update the workbook then save it. Could you give me some advice on where to go with the problem of errors ocuring in the update. e.g. if the user leaves a the date textbox blank or types text then a error 13 mismatch occurs and the program stops with the multiuser workbook open. I would like to avoid this for to reasons. 1. as its password protected i dont want the users in it.Just the form to update it. 2. if it crashes and a user leaves it open then it will prevent other users being able to update the data. My code is below if necessary. Any input would be greatfully appreciated. Private Sub CommandButton1_Click() Application.ScreenUpdating = False Do Until issave = True Dim theBk As Workbook fto = "Z:\Systemdown\" & CommandN & "\Notes.xls" Set theBk = Workbooks.Open(FileName:=fto, Password:="thunder", WriteResPassword:="thunder") If theBk.ReadOnly Then theBk.Close False issave = False Else newrow = Workbooks("Notes.xls").Sheets("data").Range("A6553 6").End(xlUp).Row + 1 Workbooks("Notes.xls").Sheets("data").Cells(newrow , 1).Value = Environ("UserName") Workbooks("Notes.xls").Sheets("data").Cells(newrow , 2).Value = Now Workbooks("Notes.xls").Sheets("data").Cells(newrow , 3).Value = namex Workbooks("Notes.xls").Sheets("data").Cells(newrow , 4).Value = team Workbooks("Notes.xls").Sheets("data").Cells(newrow , 5).Value = TextBox1.Value Workbooks("Notes.xls").Sheets("data").Cells(newrow , 6).Value = TextBox2.Value With Workbooks("Notes.xls").Sheets("data").Cells(newrow , 7) .Value = CDate(TextBox3.Text) .NumberFormat = "dd-mm-yyyy" End With Workbooks("Notes.xls").Sheets("data").Cells(newrow , 8).Value = TextBox4.Value Workbooks("Notes.xls").Sheets("data").Cells(newrow , 9).Value = TextBox5.Text Workbooks("Notes.xls").Sheets("data").Cells(newrow , 10).Value = TextBox6.Value theBk.Close True Application.ScreenUpdating = True MsgBox "Records Saved" Application.ScreenUpdating = False issave = True End If Loop Application.ScreenUpdating = False Unload Wrapform End Sub -- Regards and Thanks for any assistance. Francis Brown. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Error Handling | Excel Discussion (Misc queries) | |||
Error handling with a handling routine | Excel Programming | |||
Error handling | Excel Programming | |||
Error Handling | Excel Programming | |||
Error Handling | Excel Programming |