R
Rob
Hi,
I'm having issues with the following code that is run from a button on a
form, when first run no records are updated yet run a second time, records
are imported albeit not always every record, run several times, I get the
correct result. I'm guessing there is a fundamental coding error but can't
locate it.
Any pointers would be appreciated. Rob
Public Function ImportSales()
On Error GoTo ImportSales_Err
DoCmd.SetWarnings False
DoCmd.TransferDatabase acImport, "dBase IV", "N:\MBM\DBASE\IMPORTS",
acTable, "MBMSALE.DBF", "MBMSALE"
DoCmd.RunSQL "UPDATE salemain AS d1, MBMSALE AS d2 SET d1.GLASS =
d2.GLASS, d1.TOTGALL = d2.TOTGALL, d1.JUCVAL = d2.JUCVAL, d1.SEASPROD =
d2.SEASPROD, d1.TOTPROD = d2.TOTPROD, d1.TURNOVER = d2.TURNOVER WHERE
(((d2.ACCNO)=d1.ACCNO) And ((d2.WKEND)=d1.WKEND));"
DoCmd.RunSQL "INSERT INTO SALEMAIN ( ACCNO, WKEND, GLASS, TOTGALL,
JUCVAL, SEASPROD, TOTPROD, TURNOVER )SELECT DISTINCTROW MBMSALE.ACCNO,
MBMSALE.WKEND, MBMSALE.GLASS, MBMSALE.TOTGALL, MBMSALE.JUCVAL,
MBMSALE.SEASPROD, MBMSALE.TOTPROD, MBMSALE.TURNOVER FROM MBMSALE LEFT JOIN
SALEMAIN ON (MBMSALE.ACCNO = SALEMAIN.ACCNO) AND (MBMSALE.WKEND =
SALEMAIN.WKEND)WHERE (((SALEMAIN.ACCNO) Is Null) AND ((SALEMAIN.WKEND) Is
Null));"
DoCmd.DeleteObject acTable, "MBMSALE"
DoCmd.SetWarnings True
ImportSales_Exit:
Exit Function
ImportSales_Err:
MsgBox Error$
Resume ImportSales_Exit
End Function
I'm having issues with the following code that is run from a button on a
form, when first run no records are updated yet run a second time, records
are imported albeit not always every record, run several times, I get the
correct result. I'm guessing there is a fundamental coding error but can't
locate it.
Any pointers would be appreciated. Rob
Public Function ImportSales()
On Error GoTo ImportSales_Err
DoCmd.SetWarnings False
DoCmd.TransferDatabase acImport, "dBase IV", "N:\MBM\DBASE\IMPORTS",
acTable, "MBMSALE.DBF", "MBMSALE"
DoCmd.RunSQL "UPDATE salemain AS d1, MBMSALE AS d2 SET d1.GLASS =
d2.GLASS, d1.TOTGALL = d2.TOTGALL, d1.JUCVAL = d2.JUCVAL, d1.SEASPROD =
d2.SEASPROD, d1.TOTPROD = d2.TOTPROD, d1.TURNOVER = d2.TURNOVER WHERE
(((d2.ACCNO)=d1.ACCNO) And ((d2.WKEND)=d1.WKEND));"
DoCmd.RunSQL "INSERT INTO SALEMAIN ( ACCNO, WKEND, GLASS, TOTGALL,
JUCVAL, SEASPROD, TOTPROD, TURNOVER )SELECT DISTINCTROW MBMSALE.ACCNO,
MBMSALE.WKEND, MBMSALE.GLASS, MBMSALE.TOTGALL, MBMSALE.JUCVAL,
MBMSALE.SEASPROD, MBMSALE.TOTPROD, MBMSALE.TURNOVER FROM MBMSALE LEFT JOIN
SALEMAIN ON (MBMSALE.ACCNO = SALEMAIN.ACCNO) AND (MBMSALE.WKEND =
SALEMAIN.WKEND)WHERE (((SALEMAIN.ACCNO) Is Null) AND ((SALEMAIN.WKEND) Is
Null));"
DoCmd.DeleteObject acTable, "MBMSALE"
DoCmd.SetWarnings True
ImportSales_Exit:
Exit Function
ImportSales_Err:
MsgBox Error$
Resume ImportSales_Exit
End Function