I am trying to load my form but I don't believe that my VBA codes are correct. Whenever I try to dump the information to another worksheet in the workbook and I keep getting error 1004 method range of object changed. My cancel button closes the form but my add information does not work. Below are the codes that I am using for the request form.
'Private Sub UserForm_Click()
'
'requestform.Show
'
'End Sub
Option Explicit
Private Sub UserForm_Initialize()
Me.priority.List = Range("PriorityLevel").Value
Me.request.List = Range("TypeofRequest").Value
Me.category.List = Range("Category").Value
End Sub
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Master CCO CCB Document List")
'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'check for a email
With Me
If Trim(.email.Value) = "" Then
.email.SetFocus
MsgBox "Please enter the email of the request originator"
Exit Sub
End If
'auto populate
'copy the data to the database
ws.Cells(iRow, 1).Value = .email.Value
ws.Cells(iRow, 2).Value = .change.Value
ws.Cells(iRow, 3).Value = .store.Value
ws.Cells(iRow, 4).Value = .priority.Value
ws.Cells(iRow, 5).Value = .request.Value
ws.Cells(iRow, 6).Value = .category.Value
ws.Cells(iRow, 7).Value = .document.Value
ws.Cells(iRow, 8).Value = .lob.Value
ws.Cells(iRow, 9).Value = .audience.Value
ws.Cells(iRow, 10).Value = .current.Value
ws.Cells(iRow, 11).Value = .desired.Value
ws.Cells(iRow, 12).Value = .reason.Value
ws.Cells(iRow, 13).Value = .roll.Value
ws.Cells(iRow, 14).Value = .location.Value
ws.Cells(iRow, 15).Value = .approve.Value
ws.Cells(iRow, 16).Value = .form.Value
ws.Cells(iRow, 17).Value = Format(Now, "mm/dd/yy hh:mm")
'clear the data
.email.Value = ""
.change.Value = ""
.store.Value = ""
.priority.Value = ""
.request.Value = ""
.category.Value = ""
.document.Value = ""
.lob.Value = ""
.audience.Value = ""
.current.Value = ""
.desired.Value = ""
.reason.Value = ""
.roll.Value = ""
.location.Value = ""
.approve.Value = ""
.form.Value = ""
.email.SetFocus
End Sub
If Me.email.Value = "" Then
MsgBox "Please enter the email of the requester.", vbExclamation, "CCO CCB Document Change Request Form"
Me.email.SetFocus
Exit Sub
End If
Private Sub cmcancel_Click()
Unload Me
End Sub
'Private Sub UserForm_Click()
'
'requestform.Show
'
'End Sub
Option Explicit
Private Sub UserForm_Initialize()
Me.priority.List = Range("PriorityLevel").Value
Me.request.List = Range("TypeofRequest").Value
Me.category.List = Range("Category").Value
End Sub
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Master CCO CCB Document List")
'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'check for a email
With Me
If Trim(.email.Value) = "" Then
.email.SetFocus
MsgBox "Please enter the email of the request originator"
Exit Sub
End If
'auto populate
'copy the data to the database
ws.Cells(iRow, 1).Value = .email.Value
ws.Cells(iRow, 2).Value = .change.Value
ws.Cells(iRow, 3).Value = .store.Value
ws.Cells(iRow, 4).Value = .priority.Value
ws.Cells(iRow, 5).Value = .request.Value
ws.Cells(iRow, 6).Value = .category.Value
ws.Cells(iRow, 7).Value = .document.Value
ws.Cells(iRow, 8).Value = .lob.Value
ws.Cells(iRow, 9).Value = .audience.Value
ws.Cells(iRow, 10).Value = .current.Value
ws.Cells(iRow, 11).Value = .desired.Value
ws.Cells(iRow, 12).Value = .reason.Value
ws.Cells(iRow, 13).Value = .roll.Value
ws.Cells(iRow, 14).Value = .location.Value
ws.Cells(iRow, 15).Value = .approve.Value
ws.Cells(iRow, 16).Value = .form.Value
ws.Cells(iRow, 17).Value = Format(Now, "mm/dd/yy hh:mm")
'clear the data
.email.Value = ""
.change.Value = ""
.store.Value = ""
.priority.Value = ""
.request.Value = ""
.category.Value = ""
.document.Value = ""
.lob.Value = ""
.audience.Value = ""
.current.Value = ""
.desired.Value = ""
.reason.Value = ""
.roll.Value = ""
.location.Value = ""
.approve.Value = ""
.form.Value = ""
.email.SetFocus
End Sub
If Me.email.Value = "" Then
MsgBox "Please enter the email of the requester.", vbExclamation, "CCO CCB Document Change Request Form"
Me.email.SetFocus
Exit Sub
End If
Private Sub cmcancel_Click()
Unload Me
End Sub