Dim wb As Workbook
Set wb = Workbooks.Open("C:\VBAX\NewData.xlsx")
With wb
Set ws = .Worksheets("Employee Data")
'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'check for a Name number
If Trim(Me.TextBox_Name.Value) = "" Then
Me.TextBox_Name.SetFocus
MsgBox "Please complete the form"
Exit Sub
End If
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.TextBox_Name.Value
ws.Cells(iRow, 2).Value = Me.TextBox_Surname.Value
ws.Cells(iRow, 3).Value = Me.TextBox_Age.Value
ws.Cells(iRow, 4).Value = Me.TextBox_Gender.Value
ws.Cells(iRow, 5).Value = Me.TextBox_Address.Value
ws.Cells(iRow, 6).Value = Me.TextBox_City.Value
ws.Cells(iRow, 7).Value = Me.TextBox_Province.Value
ws.Cells(iRow, 8).Value = Me.TextBox_Postal_Code.Value
End With
wb.Close True