E
Eric Frohmann
Hi there.
What do I gotta do to export from a query into a text file??? When I run the
code below, I receive the following error:
"Operation is not allowed when the object is closed". This occurs when
testing if rst.RecordCount > 1. I've played with several different
permutations.
When I do a similar thing using "DoCmd.RunSQL stSql", I get a prompt
confirming I want to add records; plus how do I know if there are any
records???
On Error Resume Next
DoCmd.DeleteObject acTable, "prgTblExportStandData"
On Error GoTo Err_cfUploadData
stSql = "SELECT mnrcode, wg, type, age, ht, stkg, site, spc, fu, habu,
ecosite, survdate" _
& " INTO prgTblExportStandData FROM tblStand WHERE ((pkFlag=Yes)
AND (dtModifiedDate > #" & dtStartDate & "#));"
rst.Open stSql, cnn, adOpenStatic
If (rst.RecordCount > 1) Then
stTargetFile = emSaveAsFile("csv", "H:\")
If ((Not IsNull(stTargetFile)) And stTargetFile <> "") Then
DoCmd.TransferText acExportDelim, , "prgTblExportStandData",
stTargetFile
bSuccess = True
End If
Else
MsgBox "There is no data newer than: " & str(dtStartDate), vbOKOnly,
"No Data"
bSuccess = True
End If
TIA
What do I gotta do to export from a query into a text file??? When I run the
code below, I receive the following error:
"Operation is not allowed when the object is closed". This occurs when
testing if rst.RecordCount > 1. I've played with several different
permutations.
When I do a similar thing using "DoCmd.RunSQL stSql", I get a prompt
confirming I want to add records; plus how do I know if there are any
records???
On Error Resume Next
DoCmd.DeleteObject acTable, "prgTblExportStandData"
On Error GoTo Err_cfUploadData
stSql = "SELECT mnrcode, wg, type, age, ht, stkg, site, spc, fu, habu,
ecosite, survdate" _
& " INTO prgTblExportStandData FROM tblStand WHERE ((pkFlag=Yes)
AND (dtModifiedDate > #" & dtStartDate & "#));"
rst.Open stSql, cnn, adOpenStatic
If (rst.RecordCount > 1) Then
stTargetFile = emSaveAsFile("csv", "H:\")
If ((Not IsNull(stTargetFile)) And stTargetFile <> "") Then
DoCmd.TransferText acExportDelim, , "prgTblExportStandData",
stTargetFile
bSuccess = True
End If
Else
MsgBox "There is no data newer than: " & str(dtStartDate), vbOKOnly,
"No Data"
bSuccess = True
End If
TIA