03856me
Active Member
- Joined
- Apr 4, 2008
- Messages
- 297
I must be going about this in the wrong way so I need some help. I have come to this conclusion since 1) it is not working correctly, and 2) I can't find any other posts about this.
I have built a userform with multiple input boxes. There are currently 6 rows of like data that can be entered. I only want each row written to the database if there is data entered on that row when the Add button is executed. I am including the code for my add button as well as a few of the code groupings to write to the database. If someone could help be figure out where it is wrong - it works perfectly as long as all rows contain data, but the norm is maybe 2 of the 6 rows have data.
Thanks in advance for your help.
Private Sub cmd_add_Click()
If txt_4hrs.Value > "0" Then AddData2x4
If txt_6hrs.Value > "0" Then AddData2x6
If txt_8hrs.Value > "0" Then AddData2x8
If txt_10hrs.Value > "0" Then AddData2x10
If txt_12hrs.Value > "0" Then AddData2x12
If txt_4x4hrs.Value > "0" Then AddData4x4
ClearData
End Sub
====================================
Private Sub AddData2x4()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("pph")
iRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ws.Cells(iRow, 1).Value = Me.txt_date.Value
ws.Cells(iRow, 2).Value = "2x4"
ws.Cells(iRow, 3).Value = Me.txt_4hrs.Value
ws.Cells(iRow, 4).Value = Me.txt_4volume.Value
ws.Cells(iRow, 5).Value = Me.txt_4mdtmin.Value
End Sub
====================================
Private Sub AddData2x6()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("pph")
iRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ws.Cells(iRow, 1).Value = Me.txt_date.Value
ws.Cells(iRow, 2).Value = "2x6"
ws.Cells(iRow, 3).Value = Me.txt_6hrs.Value
ws.Cells(iRow, 4).Value = Me.txt_6volume.Value
ws.Cells(iRow, 5).Value = Me.txt_6mdtmin.Value
End Sub
I have built a userform with multiple input boxes. There are currently 6 rows of like data that can be entered. I only want each row written to the database if there is data entered on that row when the Add button is executed. I am including the code for my add button as well as a few of the code groupings to write to the database. If someone could help be figure out where it is wrong - it works perfectly as long as all rows contain data, but the norm is maybe 2 of the 6 rows have data.
Thanks in advance for your help.
Private Sub cmd_add_Click()
If txt_4hrs.Value > "0" Then AddData2x4
If txt_6hrs.Value > "0" Then AddData2x6
If txt_8hrs.Value > "0" Then AddData2x8
If txt_10hrs.Value > "0" Then AddData2x10
If txt_12hrs.Value > "0" Then AddData2x12
If txt_4x4hrs.Value > "0" Then AddData4x4
ClearData
End Sub
====================================
Private Sub AddData2x4()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("pph")
iRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ws.Cells(iRow, 1).Value = Me.txt_date.Value
ws.Cells(iRow, 2).Value = "2x4"
ws.Cells(iRow, 3).Value = Me.txt_4hrs.Value
ws.Cells(iRow, 4).Value = Me.txt_4volume.Value
ws.Cells(iRow, 5).Value = Me.txt_4mdtmin.Value
End Sub
====================================
Private Sub AddData2x6()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("pph")
iRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ws.Cells(iRow, 1).Value = Me.txt_date.Value
ws.Cells(iRow, 2).Value = "2x6"
ws.Cells(iRow, 3).Value = Me.txt_6hrs.Value
ws.Cells(iRow, 4).Value = Me.txt_6volume.Value
ws.Cells(iRow, 5).Value = Me.txt_6mdtmin.Value
End Sub