所以我有一个文件QC来验证所有必需的字段实际存在并且格式正确。 Query运行后,它会将任何错误记录放在表中。我想要做的是使用VBA将此表导出到一个文件,向客户端发送错误信息,向他们显示任何不良记录,以便他们编辑并发送回来。
Command Click 42()
DoCmd.TransferText acExportDelim, "", "QC_Table", "C:\Users\moore\Desktop\EST-" & Format$(Date, "MMM-dd-yy") & ".txt", False
MsgBox "Exported to C:\Users\moore\Desktop\EST-" & Format$(Date, "MMM-dd-yy") & ".txt"
End Sub
我用它来导出就好了但是我希望它只在表有至少1条记录时运行。我知道我应该使用if if语句我只是不确定如何填充表格。
感谢您对此事的任何帮助!
答案 0 :(得分:2)
您需要先添加支票。这会计算QC_Table中的记录数。如果数字大于零,请执行以下操作:
Command Click 42()
Dim rst as recordset
set rst=currentdb.openrecordset("Select count(*) from QC_Table")
if rst.fields(0)>0 then
DoCmd.TransferText acExportDelim, "", "QC_Table", "C:\Users\moore\Desktop\EST-" & Format$(Date, "MMM-dd-yy") & ".txt", False
MsgBox "Exported to C:\Users\moore\Desktop\EST-" & Format$(Date, "MMM-dd-yy") & ".txt"
endif
End Sub