M
MJ
We have built a database that imports data from a number of files that are
produced daily and compiles it into a single "MASTER" table. Most of the
time the user will only be importing a single day at a time, but after
weekends and when we initiate this database we will process multiple dates at
a time.
This importing process works, but we want to put a safety into the code to
prevent loading of previously loaded dates.
My initial thought was a simple If then-Else where:
========
Private Sub CmdImport_Click() 'Import Files -- using the dates input on
the form
On Error GoTo Err_CmdImport_Click
Dim dbMyDB As Database
Dim StartDate, EndDate, PrevDate As Date
Dim strStart, strStart2, DateComplete, strEnd As String
Dim d, DaystoImport As Integer
Set dbMyDB = CurrentDb
DoCmd.SetWarnings False
PrevDate = SafetyCheck.LastRunDate ' Added to check for date of the
last time
' this
import function was run, to
' prevent
overwriting exisiting data
' with older
data.
StartDate = Me.StartDate
EndDate = Me.EndDate
If (PrevDate <= StartDate) then
MsgBox "Re-Enter your 'Start Date', it must be AFTER " & _
DateLastStored, vbCritical
...
Else
DaystoImport = (EndDate - StartDate)
For d = 0 To DaystoImport ' Added DateAdd function to handle
calendar
' issues (EOM) and
changed when the date is
' incremented (prior
to converting date to
' string variable)
for input file naming.
DateComplete = Format(DateAdd("d", d, StartDate), "mm/dd/yyyy")
strStart = Format(DateAdd("d", d, StartDate), "yymmdd")
strStart2 = Format(DateAdd("d", d, StartDate), "mmdd")
Import files loop...
Next d
SafetyCheck.LastRunDate = EndDate
' Added to store the date of the last
files
' imported.
MsgBox vbNewLine & vbNewLine & "File(s) Importing Completed" & _
vbNewLine & vbNewLine, vbOKOnly
DoCmd.SetWarnings True
End If
Exit_CmdImport_Click:
Exit Sub
Err_CmdImport_Click:
MsgBox Err.Description
Resume Exit_CmdImport_Click
End Sub
=========
Issues:
(1) Storing the "End Date" into a table with a single record and entry.
(2) Retrieving the DateLastStored from that table to make the
comparison.
*
* Does anyone have any inputs on how to make this idea work?
*
Or... my second thought was to somehow link the DateLastStored (mentioned
above) to the UserInterface form so that the User only needs to enter the end
date of their importing. I would need to tweak the way the dates are handled
within the import loop, but I would have similar issues as above plus...
Issues (continued):
(3) Linking the date stored in the table with a single record and
entry (DateLastStored) to the "Start Date" on the UserInterface form.
*
* Does anyone have any inputs on how to make either of these ideas work?
*
I sincerely hope that I have included enough information to resolve my
problems. Thank you in advance for your assistance and inputs.
MJ
produced daily and compiles it into a single "MASTER" table. Most of the
time the user will only be importing a single day at a time, but after
weekends and when we initiate this database we will process multiple dates at
a time.
This importing process works, but we want to put a safety into the code to
prevent loading of previously loaded dates.
My initial thought was a simple If then-Else where:
========
Private Sub CmdImport_Click() 'Import Files -- using the dates input on
the form
On Error GoTo Err_CmdImport_Click
Dim dbMyDB As Database
Dim StartDate, EndDate, PrevDate As Date
Dim strStart, strStart2, DateComplete, strEnd As String
Dim d, DaystoImport As Integer
Set dbMyDB = CurrentDb
DoCmd.SetWarnings False
PrevDate = SafetyCheck.LastRunDate ' Added to check for date of the
last time
' this
import function was run, to
' prevent
overwriting exisiting data
' with older
data.
StartDate = Me.StartDate
EndDate = Me.EndDate
If (PrevDate <= StartDate) then
MsgBox "Re-Enter your 'Start Date', it must be AFTER " & _
DateLastStored, vbCritical
...
Else
DaystoImport = (EndDate - StartDate)
For d = 0 To DaystoImport ' Added DateAdd function to handle
calendar
' issues (EOM) and
changed when the date is
' incremented (prior
to converting date to
' string variable)
for input file naming.
DateComplete = Format(DateAdd("d", d, StartDate), "mm/dd/yyyy")
strStart = Format(DateAdd("d", d, StartDate), "yymmdd")
strStart2 = Format(DateAdd("d", d, StartDate), "mmdd")
Import files loop...
Next d
SafetyCheck.LastRunDate = EndDate
' Added to store the date of the last
files
' imported.
MsgBox vbNewLine & vbNewLine & "File(s) Importing Completed" & _
vbNewLine & vbNewLine, vbOKOnly
DoCmd.SetWarnings True
End If
Exit_CmdImport_Click:
Exit Sub
Err_CmdImport_Click:
MsgBox Err.Description
Resume Exit_CmdImport_Click
End Sub
=========
Issues:
(1) Storing the "End Date" into a table with a single record and entry.
(2) Retrieving the DateLastStored from that table to make the
comparison.
*
* Does anyone have any inputs on how to make this idea work?
*
Or... my second thought was to somehow link the DateLastStored (mentioned
above) to the UserInterface form so that the User only needs to enter the end
date of their importing. I would need to tweak the way the dates are handled
within the import loop, but I would have similar issues as above plus...
Issues (continued):
(3) Linking the date stored in the table with a single record and
entry (DateLastStored) to the "Start Date" on the UserInterface form.
*
* Does anyone have any inputs on how to make either of these ideas work?
*
I sincerely hope that I have included enough information to resolve my
problems. Thank you in advance for your assistance and inputs.
MJ