Private Sub Combo10_BeforeUpdate(Cancel As Integer)
End Sub
Private Sub Combo18_BeforeUpdate(Cancel As Integer)
End Sub
Private Sub Combo20_BeforeUpdate(Cancel As Integer)
End Sub
Private Sub Command36_Click()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim rstnew As DAO.Recordset
Dim StationsArray() As String
Dim ChemicalArray() As String
Dim DataIDArray() As Integer
Dim DateArray() As String
Dim TimeArray() As String
Dim CurrentArrayRec As Integer
Dim TempDataID As String
Dim Last As Boolean
Dim NoTime As Boolean
Dim i As Integer
Dim j As Integer
Dim Temp As String
Dim fldLoop As Field
Dim prpLoop As Property
Dim tdfNew As TableDef
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("LAB2", dbOpenDynaset)
CurrentArrayRec = 0
i = 0
Last = False
NoTime = False
' Create a new TableDef object.
Set tdfNew = dbs.CreateTableDef("New")
With rst
ReDim Preserve DataIDArray(i)
ReDim Preserve DateArray(i)
ReDim Preserve TimeArray(i)
ReDim Preserve StationsArray(i)
rst.MoveFirst
'Generates The DataID, Date, Time, Station Arrays
Do While Not rst.EOF
'Checks if the DataId is already in the array
For i = 0 To UBound(DataIDArray())
'If the DataID is already in the array
'it exits out of the For Loop
If DataIDArray(i) = !Chemical_DataID Then
Exit For
End If
'if it is at the last record, and it hasn't found the DataID
'it will add the DataID, Date, Time, Station to their Array
If i = UBound(DataIDArray()) Then
DataIDArray(i) = !Chemical_DataID
CurIDRec = 1 + CurIDRec
ReDim Preserve DataIDArray(i + 1)
DateArray(i) = !Date_Collected
ReDim Preserve DateArray(i + 1)
StationsArray(i) = !Station
ReDim Preserve StationsArray(i + 1)
'If Lab is Chemtech it doesn't use the Time Array
'Because chemtech doesn't use the time field
'Sets NoTime to True so later in the code it doesn't
'Insert Time as a Field
If ![Lab] = "Chemtech" Then
NoTime = True
Else
TimeArray(i) = ![Time Collected]
ReDim Preserve TimeArray(i + 1)
End If
End If
Next i
rst.MoveNext
Loop
i = 0
'Generates the Chemical Array
ReDim Preserve ChemicalArray(i)
rst.MoveFirst
Do While Not rst.EOF
'Checks if the parameter is already in the array
For i = 0 To CurrentArrayRec
'If the parameter is already in the array
'it exits out of the For Loop
If ChemicalArray(i) = !parameter Then
Exit For
End If
'if it is at the last record, and it hasn't found the parameter
'it will add the parameter to the Array
If i = CurrentArrayRec Then
ChemicalArray(i) = !parameter
CurrentArrayRec = 1 + CurrentArrayRec
ReDim Preserve ChemicalArray(i + 1)
Exit For
End If
Next i
rst.MoveNext
Loop
End With
With tdfNew
' Create fields and append them to the new TableDef
' object. This must be done before appending the
' TableDef object to the TableDefs collection of the
' Current Db
'Generate other fields here
.Fields.Append .CreateField("Station", dbText)
.Fields.Append .CreateField("Elevation", dbInteger)
.Fields.Append .CreateField("Riser_Length", dbInteger)
.Fields.Append .CreateField("Screen_Length", dbInteger)
.Fields.Append .CreateField("Date_Collected", dbDate)
If (NoTime = False) Then
.Fields.Append .CreateField("Time_Collected", dbText)
End If
.Fields.Append .CreateField("Matrix", dbText)
'Should generate the chemical fields from the array
For i = 0 To CurrentArrayRec
If ChemicalArray(i) = "" Then
Exit For
End If
.Fields.Append .CreateField(ChemicalArray(i), dbText)
Next i
dbs.TableDefs.Append tdfNew
End With
'//////////////////////////////////////////////////////////////////////
'Inputs the data from the lab table to the new table
Set rstnew = dbs.OpenRecordset("New", dbOpenDynaset)
rst.MoveFirst
'Generates the # of records needed and adds Station Value to new table
For i = 0 To UBound(StationsArray())
rstnew.AddNew
If StationsArray(i) = "" Then
Exit For
End If
rstnew.Fields![Station] = StationsArray(i)
rstnew.Update
Next i
rstnew.MoveFirst
For i = 0 To UBound(DateArray())
If (DateArray(i) = "") Then
Exit For
End If
rstnew.Edit
rstnew.Fields![Date_Collected] = DateArray(i)
rstnew.Update
rstnew.MoveNext
Next i
rstnew.MoveFirst
If (NoTime = False) Then
For i = 0 To UBound(TimeArray())
If (TimeArray(i) = "") Then
Exit For
End If
rstnew.Edit
rstnew.Fields![Time_Collected] = TimeArray(i)
rstnew.Update
rstnew.MoveNext
Next i
End If
rst.MoveFirst
rstnew.MoveFirst
j = 8
TempDataID = rst.Fields!Chemical_DataID
'Inserts Chemical Results
Temp = rst.Fields![Chemical_DataID]
Do While Not rst.EOF
If (rst.Fields![Chemical_DataID] <> Temp) Then
rstnew.MoveNext
End If
rstnew.Edit
For j = 6 To CurrentArrayRec + 7
If (rst.Fields![parameter] = rstnew.Fields(j).name) Then
rstnew.Fields(j) = rst.Fields![Report_Result]
Exit For
End If
Next j
Temp = rst.Fields![Chemical_DataID]
rstnew.Update
rst.MoveNext
Loop
rst.MoveFirst
rstnew.MoveFirst
i = 0
Do While Not rst.EOF And Last = False
If (rst.Fields![Station] = rstnew.Fields![Station]) Then
rstnew.Edit
rstnew.Fields![Elevation] = rst.Fields![Elevation]
rstnew.Fields![Riser_Length] = rst.Fields![RiserLength]
rstnew.Fields![Screen_Length] = rst.Fields![Screen_Length]
rstnew.Fields![Matrix] = rst.Fields![Matrix]
rstnew.Update
If (rstnew.Fields![Station] = StationsArray(UBound(StationsArray()) - 1)) Then
Last = True
End If
rstnew.MoveNext
i = 1 + i
rst.MoveNext
Else
rst.MoveNext
End If
Loop
ErrorHandlerExit:
Exit Sub
ErrorHandler:
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume ErrorHandlerExit
dbs.Close
End Sub