I have an excel 2007 work book that requires input from the user in the form of a table. I have created the data input form, and it maps to a tab in the work book, however, resently it has started stopping when updating the data.
The associated code is provided below:
[pre]
[/pre]
The error occurs in the section 'copy the data to the database'
Any assistance would be greatly appreciated.
Plesae note, I am fairly new regarding VBA
The associated code is provided below:
[pre]
Code:
Private Sub commentAdd_Click()
Dim lRow As Long
Dim lPart As Long
Dim ws As Worksheet
Set ws = Worksheets("Comments")
Me.txtDate.Value = Format(Date, "Medium Date")
'find first empty row in database
lRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'check for a part number
If Trim(Me.txtName.Value) = "" Then
Me.txtName.SetFocus
MsgBox "Please enter your User Name"
Exit Sub
End If
'copy the data to the database
With ws
.Cells(lRow, 1).Value = Me.txtName.Value
.Cells(lRow, 2).Value = Me.txtDate.Value
.Cells(lRow, 3).Value = Me.ComboBox1.Value
.Cells(lRow, 4).Value = Me.txtComment.Value
.Cells(lRow, 5).Value = Me.TxtSA.Value
End With
'clear the data
Me.txtName.Value = ""
Me.txtDate.Value = Format(Date, "Medium Date")
Me.ComboBox1.Value = ""
Me.txtComment.Value = ""
Me.txtName.SetFocus
End Sub
The error occurs in the section 'copy the data to the database'
Any assistance would be greatly appreciated.
Plesae note, I am fairly new regarding VBA