F
Fysh
Using Access 2k. I have form with a button, when I press this I have a
procedure, which deletes information in about 8 temp tables, then it imports
delaminated txt files into these tables. I then have it run some update
queries and/or append queries for the permanent tables. However I have one,
which is giving me nightmares for the past 3 days. I tried using queries and
code, but for some reason I can get it to append the right record. The
problem is I have several stand-alone systems, which import data into one
system via txt files. Here is my code hopefully someone can point me in the
right direction. I have tried several variations but nothing works it keeps
find the first record in tblPracticalResults and that's it.
Dim dbs As dao.Database
Dim rst As dao.Recordset
Dim rst2 As dao.Recordset
Dim rst3 As dao.Recordset
Dim rst4 As dao.Recordset
Dim strSQL As String
Dim strSql2 As String
Dim strWhere As Variant
Dim varRec As Integer
Dim varStudent As Integer
Dim varPracID As Integer
Dim varID As Variant
Dim varPRID As Variant
Dim k as Integer
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("tblCommentsTemp")
Set rst2 = dbs.OpenRecordset("tblPracticalResultsTemp")
rst.MoveLast
rst.MoveFirst
varRec = rst.RecordCount
For k = 1 To varRec
varStudent = DLookup("StuID", "tblStudents", "SID= '" & DLookup("SID",
"tblStudentsTemp", "StuID = " _
& rst![StudentID]) & "'")
strSql2 = ("SELECT PracticalResultsID " & " FROM tblPracticalResults " & "
WHERE (([PRID] = '" & (varA & "/" & DLookup("PracticalIDNumber", _
"tblPracticalData", "UniquePracticalIdentifier ='" & _
DLookup("UniquePracticalIdentifier", "tblPracticalDataTemp",
"PracticalIDNumber= " _
& DLookup("PracticalIDNumber", "tblPracticalResultsTemp",
"PracticalResultsID= " & _
rst![PracticalResultsID])) & "'") & "/" & rst2![PractCATID]
& "/" & rst2![Attribute] _
& "/" & rst2![AttributeDetail]) & "'" & "))")
Debug.Print strSql2
Set rst3 = dbs.OpenRecordset(strSql2)
strWhere = "PracticalResultsID = " & rst3![PracticalResultsID]
rst3.FindFirst strWhere
If Not NoMatch Then
strSQL = "Insert Into tblComments (CStuID, Comments, PracticalResultsID,
StudentID,TimeStampField,Reason)" & _
"SELECT " & "'" & (varA & "/" & rst3![PracticalResultsID] &
"/" & rst![Reason] & "/" & varStudent) _
& "'" & "," & "'" & rst![Comments] & "'" & "," &
rst3![PracticalResultsID] & "," & varStudent & "," & "'" _
& rst![TimeStampField] & "'" & "," & "'" & rst![Reason] & "';"
CurrentDb.Execute strSQL, dbFailOnError
End If
rst.MoveNext
Next k
rst.Close
rst2.Close
rst3.Close
Set rst = Nothing
Set rst2 = Nothing
Set rst3 = Nothing
Set dbs = Nothing
procedure, which deletes information in about 8 temp tables, then it imports
delaminated txt files into these tables. I then have it run some update
queries and/or append queries for the permanent tables. However I have one,
which is giving me nightmares for the past 3 days. I tried using queries and
code, but for some reason I can get it to append the right record. The
problem is I have several stand-alone systems, which import data into one
system via txt files. Here is my code hopefully someone can point me in the
right direction. I have tried several variations but nothing works it keeps
find the first record in tblPracticalResults and that's it.
Dim dbs As dao.Database
Dim rst As dao.Recordset
Dim rst2 As dao.Recordset
Dim rst3 As dao.Recordset
Dim rst4 As dao.Recordset
Dim strSQL As String
Dim strSql2 As String
Dim strWhere As Variant
Dim varRec As Integer
Dim varStudent As Integer
Dim varPracID As Integer
Dim varID As Variant
Dim varPRID As Variant
Dim k as Integer
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("tblCommentsTemp")
Set rst2 = dbs.OpenRecordset("tblPracticalResultsTemp")
rst.MoveLast
rst.MoveFirst
varRec = rst.RecordCount
For k = 1 To varRec
varStudent = DLookup("StuID", "tblStudents", "SID= '" & DLookup("SID",
"tblStudentsTemp", "StuID = " _
& rst![StudentID]) & "'")
strSql2 = ("SELECT PracticalResultsID " & " FROM tblPracticalResults " & "
WHERE (([PRID] = '" & (varA & "/" & DLookup("PracticalIDNumber", _
"tblPracticalData", "UniquePracticalIdentifier ='" & _
DLookup("UniquePracticalIdentifier", "tblPracticalDataTemp",
"PracticalIDNumber= " _
& DLookup("PracticalIDNumber", "tblPracticalResultsTemp",
"PracticalResultsID= " & _
rst![PracticalResultsID])) & "'") & "/" & rst2![PractCATID]
& "/" & rst2![Attribute] _
& "/" & rst2![AttributeDetail]) & "'" & "))")
Debug.Print strSql2
Set rst3 = dbs.OpenRecordset(strSql2)
strWhere = "PracticalResultsID = " & rst3![PracticalResultsID]
rst3.FindFirst strWhere
If Not NoMatch Then
strSQL = "Insert Into tblComments (CStuID, Comments, PracticalResultsID,
StudentID,TimeStampField,Reason)" & _
"SELECT " & "'" & (varA & "/" & rst3![PracticalResultsID] &
"/" & rst![Reason] & "/" & varStudent) _
& "'" & "," & "'" & rst![Comments] & "'" & "," &
rst3![PracticalResultsID] & "," & varStudent & "," & "'" _
& rst![TimeStampField] & "'" & "," & "'" & rst![Reason] & "';"
CurrentDb.Execute strSQL, dbFailOnError
End If
rst.MoveNext
Next k
rst.Close
rst2.Close
rst3.Close
Set rst = Nothing
Set rst2 = Nothing
Set rst3 = Nothing
Set dbs = Nothing