G
Guest
I have created a simple procedure to assign values form various controls on a
form to an array and then update the data into a table, however, there is a
possibility that some of the controls will not contain data and therefore I
do not want the procedure to add null values to my table. I have tried to
control this with an If..Then statement, but I can't get it to read the array
values as Null and skip it. How can this be done?
Dim rs As New ADODB.Recordset
Dim WorkAssignment(10) As Variant 'An Array that contains work assignment.
Dim Hours(10) As Variant 'An Array that contains hours.
Dim intCount As Integer
WorkAssignment(0) = cboProjectName1
WorkAssignment(1) = cboProjectName2
WorkAssignment(2) = cboProjectName3
WorkAssignment(3) = cboProjectName4
WorkAssignment(4) = cboProjectName5
WorkAssignment(5) = "BPI"
WorkAssignment(6) = "Training"
WorkAssignment(7) = "Out of Office"
WorkAssignment(8) = "Holiday"
WorkAssignment(9) = "Swiss Army"
WorkAssignment(10) = "Other"
Hours(0) = txtHours1
Hours(1) = txtHours2
Hours(2) = txtHours3
Hours(3) = txtHours4
Hours(4) = txtHours5
Hours(5) = txtBPIHours
Hours(6) = txtTrainingHours
Hours(7) = txtOutofOfficeHours
Hours(8) = txtHolidayHours
Hours(9) = txtSwissArmyHours
Hours(10) = txtOtherHours
'Opens the BPI Resource Hours table and then updates the table with the
values in the controls.
rs.Open "tblBPIResourceHours", CurrentProject.Connection, adOpenDynamic,
adLockPessimistic
With rs
Start: For intCount = 0 To 10
If WorkAssignment(intCount) = Null Then
GoTo Start
End If
.AddNew
!ResourceName = cboBPIResourceName
!WeekOf = txtWeekOf
!WorkAssignment = WorkAssignment(intCount)
!Hours = Hours(intCount)
.Update
.MoveNext
Next intCount
End With
MsgBox "Your Hours have been saved.", , "Saved BPI Resource Hours"
form to an array and then update the data into a table, however, there is a
possibility that some of the controls will not contain data and therefore I
do not want the procedure to add null values to my table. I have tried to
control this with an If..Then statement, but I can't get it to read the array
values as Null and skip it. How can this be done?
Dim rs As New ADODB.Recordset
Dim WorkAssignment(10) As Variant 'An Array that contains work assignment.
Dim Hours(10) As Variant 'An Array that contains hours.
Dim intCount As Integer
WorkAssignment(0) = cboProjectName1
WorkAssignment(1) = cboProjectName2
WorkAssignment(2) = cboProjectName3
WorkAssignment(3) = cboProjectName4
WorkAssignment(4) = cboProjectName5
WorkAssignment(5) = "BPI"
WorkAssignment(6) = "Training"
WorkAssignment(7) = "Out of Office"
WorkAssignment(8) = "Holiday"
WorkAssignment(9) = "Swiss Army"
WorkAssignment(10) = "Other"
Hours(0) = txtHours1
Hours(1) = txtHours2
Hours(2) = txtHours3
Hours(3) = txtHours4
Hours(4) = txtHours5
Hours(5) = txtBPIHours
Hours(6) = txtTrainingHours
Hours(7) = txtOutofOfficeHours
Hours(8) = txtHolidayHours
Hours(9) = txtSwissArmyHours
Hours(10) = txtOtherHours
'Opens the BPI Resource Hours table and then updates the table with the
values in the controls.
rs.Open "tblBPIResourceHours", CurrentProject.Connection, adOpenDynamic,
adLockPessimistic
With rs
Start: For intCount = 0 To 10
If WorkAssignment(intCount) = Null Then
GoTo Start
End If
.AddNew
!ResourceName = cboBPIResourceName
!WeekOf = txtWeekOf
!WorkAssignment = WorkAssignment(intCount)
!Hours = Hours(intCount)
.Update
.MoveNext
Next intCount
End With
MsgBox "Your Hours have been saved.", , "Saved BPI Resource Hours"