by Q0pfRE » Sun, 15 Jul 2007 01:58:03
ere is the complete code.
Public Sub fncFill_GainLossDlab_Table()
'This process is used to created a data tables with screened data with
meaningful field names.
Dim strRecSet As String, strUser2 As String
Dim strSQL2 As String, strTemp As String, rstUser2 As Recordset, RecUserType
As String
Dim intloop As Integer, intCntr As Single
Dim strFldPath As String, strFldName As String
Dim varData As Variant, idxRecord As Index
'VBA or VB Script
Dim strFileName() As String, strTempArr() As String
Dim blnChkdFile As Boolean
Dim rstSource As Recordset, rstTargetTbl1 As Recordset, rstDestTbl As
Recordset, rstKeyTbl As Recordset, rstTest As Recordset
Dim rsFieldName As Field, fldTemp As Field
Dim qryDef1 As QueryDef, tmpQryDef As QueryDef
blnChkdFile = False
intCntr = 0
Set rstKeyTbl = CurrentDb.OpenRecordset("Column_Descriptors")
'VariableX = cryptic field name
'Newfieldname = meaningful field
name
rstKeyTbl.Index = "DataFieldName" 'set on VariableX above
Set rstDestTbl = CurrentDb.OpenRecordset("Tables2Process")
If (rstDestTbl.BOF And rstDestTbl.EOF) Then
Call MsgBox("Table " & rstDestTbl.Name & " is empty. Leaving
Program; Can't work like this!", vbOKOnly, "Major Error")
Exit Sub
Else
rstDestTbl.MoveLast
rstDestTbl.MoveFirst
End If
Do Until rstDestTbl.EOF
Set rstSource = CurrentDb.OpenRecordset(rstDestTbl("TblName"))
If (rstSource.BOF And rstSource.EOF) Then
Call MsgBox("No Data in " & rstDestTbl("TblName") & ". Leaving
table!", vbOKOnly, "Major Error")
Exit Sub
Else
rstSource.MoveLast
rstSource.MoveFirst
End If
strSQL2 = ""
Do Until rstSource.EOF
'Check to see if this BBN code and File name are already present
in the destination table
strSQL2 = "SELECT * FROM GainLossDlab " & _
" WHERE (GainLossDlab.BBN = '" & rstSource("ASC") &
"')" & _
" AND (GainLossDlab.SAS_DATA_SEPARATOR = '" &
rstSource("File") & "');"
Set rstTest = CurrentDb.OpenRecordset(strSQL2)
If (rstTest.EOF And rstTest.BOF) Then
blnChkdFile = True
Else
blnChkdFile = False
End If
'Move each field in the source file to the destination target
after mapping
'with the field names table("Column_Descriptors")
For Each rsFieldName In rstSource.Fields
rstKeyTbl.Seek "=", rsFieldName.Name
If (rstKeyTbl.NoMatch) Or (Not blnChkdFile And Not
blnFirstTime) Then
'Skip This field something is wrong
intCntr = intCntr + 1
Exit For ' Keep moving
Else
'Update bad field data from source
If (rstKeyTbl("NewFieldName") Like "*YYMM*") And _
(Len(rstSource(rsFieldName.Name)) < 4) _
Then
'Add leading zeros for YYMM format stripped from
original source data
For intloop = 1 To (4 -
Len(rstSource(rsFieldName.Name)))
strTemp = strT