I have a solution I previously used to import csv's from a folder based on a saved spec.
I've used a lot of iterations of this, and never had an issue.
Now I need to run that SQL import query, based on a SQL result from it. So if one column has all blanks I want to run one import query, vs another one if they aren't all blanks.
I found this below on stackoverflow (I can't link I guess, but can search "can i have a docmd method in if statement") But tried to use what they said like this:
I've debug printed out the Rec(0) and it seems to work. However, anytime I add this in, I get an error that the specification doesn't exist. I think something with the openrecordset must be messing with the import later. If I comment that out, as well as the if's then either query1 or query2 work smoothly.
What is the best way to approach this? Thanks
Code:
DoCmd.TransferText TransferType:=acLinkDelim, _
SpecificationName:="samplelink", _
TableName:="Templink", _
FileName:=strPathFile, _
HasFieldNames:=True
DoCmd.RunSQL ("SELECT *, Date() as LOAD_DATE INTO mytable FROM Templink WHERE ...")
I've used a lot of iterations of this, and never had an issue.
Now I need to run that SQL import query, based on a SQL result from it. So if one column has all blanks I want to run one import query, vs another one if they aren't all blanks.
I found this below on stackoverflow (I can't link I guess, but can search "can i have a docmd method in if statement") But tried to use what they said like this:
Code:
DoCmd.TransferText TransferType:=acLinkDelim, _
SpecificationName:="samplelink", _
TableName:="Templink", _
FileName:=strPathFile, _
HasFieldNames:=True
rec = CurrentDB.OpenRecordset("Select max(mycolumn) from Templink")
if rec(0) = "" then
DoCmd.RunSQL (Query1)
else
DoCmd.RunSQL (Query2)
end if
I've debug printed out the Rec(0) and it seems to work. However, anytime I add this in, I get an error that the specification doesn't exist. I think something with the openrecordset must be messing with the import later. If I comment that out, as well as the if's then either query1 or query2 work smoothly.
What is the best way to approach this? Thanks