Good morning. I've been tinkering with this code for sometime now and I cant seem to get it to work. When the user clicks on the NextCom command, it does add the entries to the worksheet and it does clear the form, but when the next record is submitted, it just overwrites that last one...an ongoing loop overwriting the same entry. Any help PLEASE!!! I'm a rookie when it comes to VBA so please be gentle if its jacked! Thanks in advance
NOTE: Also, I have some cells locked on the spreadsheet to negate any altering to the information...but the cells where the information is going are all unlocked
NOTE: Also, I have some cells locked on the spreadsheet to negate any altering to the information...but the cells where the information is going are all unlocked
Code:
Private Sub CloseCom_Click()
Unload Me
End Sub
Private Sub NextCom_Click()
Dim RowCount As Long
Dim ctl As Control
If Me.txtCR.Value = "" Then
MsgBox "Please enter the current reading", vbExclamation, "Invalid Reading"
Me.txtCR.SetFocus
Exit Sub
End If
If Me.cboMTUMatch.Value = "" Then
MsgBox "Does the MTU Match?", vbExclamation, "Answer Required"
Me.cboMTUMatch.SetFocus
Exit Sub
End If
If Me.cboMeterMatch.Value = "" Then
MsgBox "Does the Meter SN Match?", vbExclamation, "Answer Required"
Me.cboMeterMatch.SetFocus
Exit Sub
End If
If Me.cboBox.Value = "" Then
MsgBox "Please select Box Type", vbExclamation, "Answer Required"
Me.cboBox.SetFocus
Exit Sub
End If
If Me.cboLid.Value = "" Then
MsgBox "Please select Lid Type", vbExclamation, "Answer Required"
Me.cboLid.SetFocus
Exit Sub
End If
If Me.cboMTUType.Value = "" Then
MsgBox "Please select MTU Type", vbExclamation, "Answer Required"
Me.cboMTUType.SetFocus
Exit Sub
End If
If Me.cboMTULo.Value = "" Then
MsgBox "Please select MTU Location", vbExclamation, "Answer Required"
Me.cboMTULo.SetFocus
Exit Sub
End If
If Me.cboPitFl.Value = "" Then
MsgBox "Is the pit flooded?", vbExclamation, "Answer Required"
Me.cboPitFl.SetFocus
Exit Sub
End If
emptyRow = ActiveSheet.Cells(Rows.Count, 8).End(xlUp).Row + 1
With Worksheets("Sheet1").Range("I3")
.Offset(RowCount, 0).Value = Me.txtCR.Value
.Offset(RowCount, 1).Value = Me.cboMTUMatch.Value
.Offset(RowCount, 2).Value = Me.txtFixMTU.Value
.Offset(RowCount, 3).Value = Me.cboMeterMatch.Value
.Offset(RowCount, 4).Value = Me.txtFixMeter.Value
.Offset(RowCount, 5).Value = Me.cboBox.Value
.Offset(RowCount, 6).Value = Me.cboLid.Value
.Offset(RowCount, 7).Value = Me.cboMTUType.Value
.Offset(RowCount, 8).Value = Me.cboMTULo.Value
.Offset(RowCount, 9).Value = Me.cboPitFl.Value
End With
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
Last edited: