Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update Module

Status
Not open for further replies.

TheRiver

IS-IT--Management
Dec 18, 2003
121
GB
I have a module that imports data from text files and then I need to update the data. But I only want to update the new data that is imported.

The module is as follows:

what changes do I need to make?

Dim Create As Database, wl_import As Recordset, wl_cmds As Recordset, int1 As Long, int2 As Long, i As Integer, str_answer As String
Dim intAnswer As String
Dim str_filename As String
Dim MyDir As String
Dim MyFile As String
Dim MyArray() As String
Dim FileCounter As Integer
Dim str_censusdate As String
Dim strSQL As String


Set Create = DBEngine.Workspaces(0).Databases(0)
Set wl_import = Create.OpenRecordset("WL CMDS (RNA00)")
Set wl_cmds = Create.OpenRecordset("WL NonRes")


MyDir = "K:\WL CMDS (Current Financial Year)\Good Hope Hospital NHS Trust\Inpatient Waiting List CMDS\"
intAnswer = InputBox("What month?" & Chr(10) & Chr(13) & Chr(10) & Chr(13) & "Please ensure the month is in the abbreviated format ""Jan"" for January", vbInformation, "Select Month")

Select Case intAnswer
Case "Apr": str_filename = "01 IWL Apr*.txt"
Case "May": str_filename = "02 IWL May*.txt"
Case "Jun": str_filename = "03 IWL Jun*.txt"
Case "Jul": str_filename = "04 IWL Jul*.txt"
Case "Aug": str_filename = "05 IWL Aug*.txt"
Case "Sep": str_filename = "06 IWL Sep*.txt"
Case "Oct": str_filename = "07 IWL Oct*.txt"
Case "Nov": str_filename = "08 IWL Nov*.txt"
Case "Dec": str_filename = "09 IWL Dec*.txt"
Case "Jan": str_filename = "10 IWL Jan*.txt"
Case "Feb": str_filename = "11 IWL Feb*.txt"
Case "Mar": str_filename = "12 IWL Mar*.txt"
Case Else: Exit Function
End Select
'now loop for the matching files
MyFile = Dir(MyDir & str_filename, vbNormal)
Do While (MyFile <> &quot;&quot;)
FileCounter = FileCounter + 1
ReDim Preserve MyArray(1 To FileCounter)
MyArray(FileCounter) = MyDir & MyFile
MyFile = Dir 'Sorry missed this bit off the original code
Loop
'now iterate through the created array an import files one by one
If FileCounter > 0 Then
For i = 1 To FileCounter
DoCmd.TransferText acImportDelim, &quot;IPWL 04 RNA Import&quot;, &quot;WL CMDS (RNA00)&quot;, MyArray(i)
Next i
End If


Select Case intAnswer
Case &quot;Apr&quot;: str_censusdate = &quot;20030430&quot;
Case &quot;May&quot;: str_censusdate = &quot;20030531&quot;
Case &quot;Jun&quot;: str_censusdate = &quot;20030630&quot;
Case &quot;Jul&quot;: str_censusdate = &quot;20030731&quot;
Case &quot;Aug&quot;: str_censusdate = &quot;20030831&quot;
Case &quot;Sep&quot;: str_censusdate = &quot;20030930&quot;
Case &quot;Oct&quot;: str_censusdate = &quot;20031031&quot;
Case &quot;Nov&quot;: str_censusdate = &quot;20031130&quot;
Case &quot;Dec&quot;: str_censusdate = &quot;20031231&quot;
Case &quot;Jan&quot;: str_censusdate = &quot;20040131&quot;
Case &quot;Feb&quot;: str_censusdate = &quot;20040228&quot;
Case &quot;Mar&quot;: str_censusdate = &quot;20040331&quot;
Case Else: Exit Function
End Select

strSQL = &quot;UPDATE [WL CMDS (RNA00)] SET Census_Date = '&quot; & str_censusdate & &quot;' WHERE Census_Date <> '&quot; & str_censusdate & &quot;'&quot;
DoCmd.RunSQL strSQL


End Function
 
What exactly is not working the way you want at the moment?
&quot;But I only want to update the new data that is imported. &quot;

Assuming you are appending the new data onto the old, is this just a question of identifying which rows are the new ones?

If you do not import the Census date from the text files, surely all you need do is look for rows where the census date is null.

If you currently DO import the census date, create a new import spec that skips this column on import?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top