Error Handling

F

Francis Brown

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("A65536").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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top