Hi,
I'm currently attempting to write a small Access Database which carries out the following tasks :
1. Imports Submission files (of a text variety) to a table using TransferText
on a daily basis (many files into 1 table)
2. Imports Reject Files files (again of a text variety) to another table using Transfer Text. (again, daily, many files into 1 table)
3. Run a query which reports all submissions that haven't had a matching rejection.
(I've done a small amount of moving of files around and renaming when archiving, but that's not particularly relevant to my question).
Now the tricky part (well for me at least!). The files which I'm importing for step 2 above contain a date field, which is essential to the matching process that I need to carry out in step 3. The date format that is received is a Julian date without the year of the format NNN - eurghh. For example January 15th 2007 would be represented as 015 (as would any January 15th!).
What I need to do is one of the following :
reformat/translate this as part of the DoCmd.TransferT xt as it's imported
(I don't think this is possible!?)
or add another field which represents the date in a more usable format eg DD/MM/YY during the import process. (not sure how I'd do this)
or Add a command at the end of my import process which runs through each of the records and adds the relevant date field whilst copying it to the full repository table.
Thanks for taking the time to look at this!
Full code for step 2 is below this is driven through a button : Private Sub Command12_Click ()
On Error GoTo bImportFiles_Cl ick_Err
Dim objFS As Object, objFolder As Object
Dim objFiles As Object, objF1 As Object
Dim strFolderPath As String
strFolderPath = "C:\TESTDB\Reje ct\"
Set objFS = CreateObject("S cripting.FileSy stemObject")
Set objFolder = objFS.GetFolder (strFolderPath)
Set objFiles = objFolder.files
For Each objF1 In objFiles
If InStr(objF1.Nam e, "msg") > 0 Then
'Variables used to create and modify the file extension
Dim objFileSystem
Dim objFile
Dim strFileCopy As String
Dim strFileCopy2 As String
Dim intExtPosition As Integer
'Create an instance of the FileSystemObjec t to access
'the local file system
Set objFileSystem = CreateObject("S cripting.FileSy stemObject")
'Use the GetFile method to return a File object corresponding to the
'file in a specified path.
Set objFile = objFileSystem.G etFile(objF1)
intExtPosition = InStr(objFile.N ame, ".")
If intExtPosition > 0 Then
strFileCopy2 = Left(objFile.Na me, intExtPosition - 1)
Else
strFileCopy2 = objFile.Name
End If
strFileCopy = strFileCopy2 & ".txt"
'Create a copy of the file with a .txt extension
objFile.Copy strFolderPath & strFileCopy, True
DoCmd.TransferT ext acImportFixed, "XYZ Export Specification", "AccRejects ", strFolderPath & strFileCopy, False
MsgBox strFolderPath & objF1.Name & " loaded"
Name strFolderPath & objF1.Name As "C:\TESTDB\Reje ct\Archive\" & objF1.Name 'Move the files to the archive folder
Kill strFolderPath & strFileCopy
End If
Next
Set objF1 = Nothing
Set objFiles = Nothing
Set objFolder = Nothing
Set objFS = Nothing
bImportFiles_Cl ick_Exit:
Exit Sub
bImportFiles_Cl ick_Err:
MsgBox Err.Number & " " & Err.Description
Resume bImportFiles_Cl ick_Exit
End Sub 4 1826 ADezii 8,834
Recognized Expert Expert
Hi,
I'm currently attempting to write a small Access Database which carries out the following tasks :
1. Imports Submission files (of a text variety) to a table using TransferText
on a daily basis (many files into 1 table)
2. Imports Reject Files files (again of a text variety) to another table using Transfer Text. (again, daily, many files into 1 table)
3. Run a query which reports all submissions that haven't had a matching rejection.
(I've done a small amount of moving of files around and renaming when archiving, but that's not particularly relevant to my question).
Now the tricky part (well for me at least!). The files which I'm importing for step 2 above contain a date field, which is essential to the matching process that I need to carry out in step 3. The date format that is received is a Julian date without the year of the format NNN - eurghh. For example January 15th 2007 would be represented as 015 (as would any January 15th!).
What I need to do is one of the following :
reformat/translate this as part of the DoCmd.TransferT xt as it's imported
(I don't think this is possible!?)
or add another field which represents the date in a more usable format eg DD/MM/YY during the import process. (not sure how I'd do this)
or Add a command at the end of my import process which runs through each of the records and adds the relevant date field whilst copying it to the full repository table.
Thanks for taking the time to look at this!
Full code for step 2 is below this is driven through a button : Private Sub Command12_Click ()
On Error GoTo bImportFiles_Cl ick_Err
Dim objFS As Object, objFolder As Object
Dim objFiles As Object, objF1 As Object
Dim strFolderPath As String
strFolderPath = "C:\TESTDB\Reje ct\"
Set objFS = CreateObject("S cripting.FileSy stemObject")
Set objFolder = objFS.GetFolder (strFolderPath)
Set objFiles = objFolder.files
For Each objF1 In objFiles
If InStr(objF1.Nam e, "msg") > 0 Then
'Variables used to create and modify the file extension
Dim objFileSystem
Dim objFile
Dim strFileCopy As String
Dim strFileCopy2 As String
Dim intExtPosition As Integer
'Create an instance of the FileSystemObjec t to access
'the local file system
Set objFileSystem = CreateObject("S cripting.FileSy stemObject")
'Use the GetFile method to return a File object corresponding to the
'file in a specified path.
Set objFile = objFileSystem.G etFile(objF1)
intExtPosition = InStr(objFile.N ame, ".")
If intExtPosition > 0 Then
strFileCopy2 = Left(objFile.Na me, intExtPosition - 1)
Else
strFileCopy2 = objFile.Name
End If
strFileCopy = strFileCopy2 & ".txt"
'Create a copy of the file with a .txt extension
objFile.Copy strFolderPath & strFileCopy, True
DoCmd.TransferT ext acImportFixed, "XYZ Export Specification", "AccRejects ", strFolderPath & strFileCopy, False
MsgBox strFolderPath & objF1.Name & " loaded"
Name strFolderPath & objF1.Name As "C:\TESTDB\Reje ct\Archive\" & objF1.Name 'Move the files to the archive folder
Kill strFolderPath & strFileCopy
End If
Next
Set objF1 = Nothing
Set objFiles = Nothing
Set objFolder = Nothing
Set objFS = Nothing
bImportFiles_Cl ick_Exit:
Exit Sub
bImportFiles_Cl ick_Err:
MsgBox Err.Number & " " & Err.Description
Resume bImportFiles_Cl ick_Exit
End Sub
This should solve the Julian NNN conversion. I've made a couple assumptions on Table and Field Names. Any questions, please ask. - Dim MyDB As DAO.Database, MyRS As DAO.Recordset, T As Integer
-
Dim dteStartDate As Date
-
-
dteStartDate = #1/1/2007#
-
-
Set MyDB = CurrentDb
-
Set MyRS = MyDB.OpenRecordset("tblConvertJulian", dbOpenDynaset)
-
MyRS.MoveLast: MyRS.MoveFirst
-
-
Do While Not MyRS.EOF
-
MyRS.Edit
-
MyRS![Date] = DateAdd("d", Val(MyRS![Julian] - 1), dteStartDate)
-
MyRS.Update
-
MyRS.MoveNext
-
Loop
-
-
MyRS.Close
Thanks for the responses, they certainly help.
ADezii, yours looks to be of particular interest. I think I can get away with the date addition as long as it uses 01/01/current year for the date on which it's adding.
Couple if questions though :
T As Integer (what is this being used for is it needed for the While loop?)
MyRS.MoveLast : MyRS.MoveFirst
what does this do - from searchin MoveFirst moves to the first record of the record set but why the first bit and what does the colon represent?
If I wanted update the records into a different table (and delete them from the current table - ie move them) how would I do this?
Many Thanks,
Will
ADezii 8,834
Recognized Expert Expert
Thanks for the responses, they certainly help.
ADezii, yours looks to be of particular interest. I think I can get away with the date addition as long as it uses 01/01/current year for the date on which it's adding.
Couple if questions though :
T As Integer (what is this being used for is it needed for the While loop?)
MyRS.MoveLast : MyRS.MoveFirst
what does this do - from searchin MoveFirst moves to the first record of the record set but why the first bit and what does the colon represent?
If I wanted update the records into a different table (and delete them from the current table - ie move them) how would I do this?
Many Thanks,
Will
- Sorry, the Variable T is not being used in this context, and can be deleted.
- MyRS.MoveLast:M yRS.MoveFirst - This double move really isn't needed in this scenario, but if you need an accurate RecordCount for certain Recordsets, you can only get an accurate figure if you traverse the Recordset (manually move the Record Pointer to the end and then back.
- The Colon is just a Command separator and enables you to place several statements on the same line. I apologize since this is really not a recommended practice, but since the statements are short, I used this syntax.
- If you wish to perform this operation on another Table, just replace the Table Name in the Recordset Line to your own as illustrated in the code below:
- Set MyRS = MyDB.OpenRecordset("tblConvertJulian", dbOpenDynaset)
-
'REPLACE WITH
-
Set MyRS = MyDB.OpenRecordset("<your table name>", dbOpenDynaset)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: D Mat |
last post by:
Hi,
I'm trying to get MS Access 2000 to automatically import a series of
(~200) flat text, tab delimited, data files into a single Access table,
with consistent fields and rows.
The files have different, but somewhat logical naming structures
(ex.Jun01.txt, Jun02.txt, Jul01.txt, etc...).
Is there a relatively simple way to accomplish this,...
|
by: Dan |
last post by:
Could someone please help me with auto importing a series of data
files into an Access table. I tried to follow code given below in a
previous messagebut i'm getting error messages.
Here's my database stats:
Path: C:\Database (contains the database and all the text files to
be imported)
Text files to import: (SampleData4.txt and...
|
by: N. Graves |
last post by:
I'm planning to develop a process to import data from an external flat
file to a new table automatically. As usual I'm having a hard time
getting started on the solution because of the Access's flexibility.
Please help me with your suggestion's about the best way accomplish
this or do you know of any examples that I could review or...
|
by: ms |
last post by:
In Access 2000, I am using...
'Import Raw text to stageBMIDLog table.
DoCmd.TransferText acImportFixed, "BMIDLog Link Specification",
"stageBMIDLog", file
....to import raw records into a staging table with 3-key PK. When duplicates
are attempting import, I receive a msgbox stating the number of records that
violated the PK and asks if...
|
by: khutch |
last post by:
Not that up on MS Access. I understand that the TransferText command
can be used to import csv files into a database. Question: Does the
text file have to mirror the alignment of the table columns e.g. must
field1, field2, filed3 etc correspond to col1, col2, col3 on the
table? or can I state somewhere which columns in the text file...
| |
by: DataFreakFromUtah |
last post by:
Hello!
No question here, just a procedure for the archive.
Search critera:
count records imported count data imported count number of rows
imported
count number of records imported record import count automatically
import
and count records prompt for number of records imported import count
auto-import records
autoimport records count...
|
by: Typehigh |
last post by:
HELP! I don't know what happened. I have an MS_Access 2000 application
that imports 20 data files; some Excel, some fixed-length txt and some
tab delimited.
I use "DoCmd.TransferSpreadsheet . . .", "DoCmd.TransferText
acImportFixed, . . ." and "DoCmd.TransferText acImportDelim, . . ." to
import the data into the database.
I have created...
|
by: Bill |
last post by:
I'm trying to use a command button to the same thing as going to the
file menu and doing a Get External Data command to make the import
process easier for some end users. I'm using Access 2k, I have the
following code but I can't seem to get it to work properly.
Private Sub Command18_Click()
Dim strFileName As String
Dim strPath As String...
|
by: Sean Howard |
last post by:
I have a strange problem linking tab delimited text files in Access 2000
(I am running Windows XP), please try this and let me know if I am going
mad.
Step 1.
Create the tab-delimited text file below in WordPad and call the file
"HeaderYES.txt" (the space between the two fields is actually a tab):-
"Column1" "Column2"
1 ...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |