J
javablood
I tried a make table SQL and now an append SQL in a form to combine data from
two tables into one. The end result is no data. However, if I just use a
stand alone query (or call it from the form) it works fine! I hope someone
can see the error of my ways! Here is the code:
Private Sub cmdbutrun_Click()
On Error GoTo Err_cmdbutrun_Click
Dim strSQL As String
Dim strSQLa As String
DoCmd.SetWarnings False
strSQL = "Delete * from tblSWTPZnew" ' delete data before append
' append new data
strSQLa = "INSERT INTO tblSWTPZnew ( STATION_ID, SAMPLE_DATE,
SAMPLE_TIME, GW_ELEV )" & _
"SELECT TagTable.TagName AS STATION_ID,
Format([FloatTable].[DateAndTime],""mm/dd/yy"") " & _
"AS SAMPLE_DATE, Format([FloatTable].[DateAndTime],""hh:nn:ss"") AS
SAMPLE_TIME, FloatTable.Val AS GW_ELEV " & _
"FROM FloatTable INNER JOIN TagTable ON FloatTable.TagIndex =
TagTable.TagIndex " & _
"WHERE (((Format([FloatTable].[DateAndTime],""mm/dd/yy"")) " & _
"Between [Forms]![frmRun]![lbodatbegin] And
[Forms]![frmRun]![lbodatend])) " & _
"ORDER BY TagTable.TagName,
Format([FloatTable].[DateAndTime],""mm/dd/yy"");"
DoCmd.RunSQL strSQLa
DoCmd.SetWarnings True
' check table for records
' -----------------------
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblSWTPZnew")
If rst.EOF = True And rst.BOF = True Then ' there are no records in
the recordset
ChngData = MsgBox("There are no data in the table!",
vbInformation, "No Records!")
rst.Close
Set rst = Nothing
Set dbs = Nothing
End If
' -----------------------
Exit_cmdbutrun_Click:
Exit Sub
Err_cmdbutrun_Click:
MsgBox Err.Description
Resume Exit_cmdbutrun_Click
End Sub
Thanks,
two tables into one. The end result is no data. However, if I just use a
stand alone query (or call it from the form) it works fine! I hope someone
can see the error of my ways! Here is the code:
Private Sub cmdbutrun_Click()
On Error GoTo Err_cmdbutrun_Click
Dim strSQL As String
Dim strSQLa As String
DoCmd.SetWarnings False
strSQL = "Delete * from tblSWTPZnew" ' delete data before append
' append new data
strSQLa = "INSERT INTO tblSWTPZnew ( STATION_ID, SAMPLE_DATE,
SAMPLE_TIME, GW_ELEV )" & _
"SELECT TagTable.TagName AS STATION_ID,
Format([FloatTable].[DateAndTime],""mm/dd/yy"") " & _
"AS SAMPLE_DATE, Format([FloatTable].[DateAndTime],""hh:nn:ss"") AS
SAMPLE_TIME, FloatTable.Val AS GW_ELEV " & _
"FROM FloatTable INNER JOIN TagTable ON FloatTable.TagIndex =
TagTable.TagIndex " & _
"WHERE (((Format([FloatTable].[DateAndTime],""mm/dd/yy"")) " & _
"Between [Forms]![frmRun]![lbodatbegin] And
[Forms]![frmRun]![lbodatend])) " & _
"ORDER BY TagTable.TagName,
Format([FloatTable].[DateAndTime],""mm/dd/yy"");"
DoCmd.RunSQL strSQLa
DoCmd.SetWarnings True
' check table for records
' -----------------------
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblSWTPZnew")
If rst.EOF = True And rst.BOF = True Then ' there are no records in
the recordset
ChngData = MsgBox("There are no data in the table!",
vbInformation, "No Records!")
rst.Close
Set rst = Nothing
Set dbs = Nothing
End If
' -----------------------
Exit_cmdbutrun_Click:
Exit Sub
Err_cmdbutrun_Click:
MsgBox Err.Description
Resume Exit_cmdbutrun_Click
End Sub
Thanks,