Mooseman60
11-18-2010, 06:42 AM
:banghead:Can anyone tell me why this error Run-time error: 9 Subscript Out of Range
comes up on this line of code in the attached code
Workbooks("Defined Name Lists.xls").Worksheets("ContractorsDetails").Range("A2").Value = txtContractorsName.Text
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Workbooks("Defined Name Lists.xls").Worksheets("ContractorsDetails").Range("A2").Value = txtContractorsName.Text
'find first empty row in database
Set ws = Workbooks("Defined Name Lists.xls").Worksheets("ContractorsDetails")
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
'check for a ContractorsName
If Trim(Me.txtContractorsName.Value) = "" Then
Me.txtContractorsName.SetFocus
MsgBox "Please enter a Contractors Name"
Exit Sub
End If
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtContractorsName.Value
'clear the data
Me.txtContractorsName.Value = ""
Me.txtContractorsName.SetFocus
End Sub
comes up on this line of code in the attached code
Workbooks("Defined Name Lists.xls").Worksheets("ContractorsDetails").Range("A2").Value = txtContractorsName.Text
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Workbooks("Defined Name Lists.xls").Worksheets("ContractorsDetails").Range("A2").Value = txtContractorsName.Text
'find first empty row in database
Set ws = Workbooks("Defined Name Lists.xls").Worksheets("ContractorsDetails")
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
'check for a ContractorsName
If Trim(Me.txtContractorsName.Value) = "" Then
Me.txtContractorsName.SetFocus
MsgBox "Please enter a Contractors Name"
Exit Sub
End If
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtContractorsName.Value
'clear the data
Me.txtContractorsName.Value = ""
Me.txtContractorsName.SetFocus
End Sub