No this now flags up an error on the "RowCount = .Cells(.Rows.Count, 1).End(xlUp).Row - .Row + 1"
Private Sub CmdEnter_Click()
Dim RowCount As Long
Dim ctl As Control
' Check User Input
If Me.TxtLocation = "" Then
MsgBox "Please enter a Location."
Me.TxtLocation.SetFocus
Exit Sub
End If
If Me.TextBox2 = "" Then
MsgBox "Please enter Address."
Me.TextBox2.SetFocus
Exit Sub
End If
If Me.TextBox3 = "" Then
MsgBox "Please enter a Town."
Me.TextBox3.SetFocus
Exit Sub
End If
If Me.TextBox4 = "" Then
MsgBox "Please enter County."
Me.TextBox4.SetFocus
Exit Sub
End If
If Me.TextBox5 = "" Then
MsgBox "Please enter Postcode."
Me.TextBox5.SetFocus
Exit Sub
End If
If Me.TextBox6 = "" Then
MsgBox "Please enter Site Telephone Number."
Me.TextBox6.SetFocus
Exit Sub
End If
'Write Data to Worksheet
With Worksheets("Data Form")
RowCount = .Cells(.Rows.Count, 1).End(xlUp).Row - .Row + 1
.Offset(RowCount, 0).Value = Me.TextBox1.Value
.Offset(RowCount, 1).Value = Me.TextBox2.Value
.Offset(RowCount, 2).Value = Me.TextBox3.Value
.Offset(RowCount, 3).Value = Me.TextBox4.Value
.Offset(RowCount, 4).Value = Me.TextBox5.Value
.Offset(RowCount, 5).Value = Me.TextBox6.Value
.Offset(RowCount, 6).Value = Me.TextBox7.Value
.Offset(RowCount, 7).Value = Me.ComboBox1.Value
.Offset(RowCount, 8).Value = Me.ComboBox2.Value
.Offset(RowCount, 9).Value = Me.TextBox13.Value
.Offset(RowCount, 10).Value = Me.TextBox14.Value
.Offset(RowCount, 11).Value = Me.TextBox15.Value
.Offset(RowCount, 12).Value = Me.TextBox16.Value
.Offset(RowCount, 12).Value = Me.TextBox17.Value
End With
' Clear the form
For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
ctl.Value = ""
ElseIf TypeName(ctl) = "CheckBox" Then
ctl.Value = False
End If
Next ctl
End Sub
Bookmarks