Hello!
I am working with an Access Database (Access 2002) that contains a form that is supposed to import a CSV. However, because some of the integers contained in the CSV are too large for Access to handle (regardless of the number format I select for the field), I'm going to need to do some data transformations on the CSV before I can import it into Access.
An example of a row from this CSV would be:
| Client IP | Requests | Views | Time | Total Bytes | Bytes Received | Bytes Sent |
------------------------------------------------------------------------------------------
| 192.168.192.168 | 313170 | 7198 | 74330 | 5718744799 | 5416925116 | 301819683 |
So, this is the code that I have in place to perform the import:
Private Sub cmdImport_Click()
Dim ReportDate As String
ReportDate = Me!ReportMonth & "/01/" & Me!ReportYear
If IsNull(Me.txtFileName) Or Len(Me.txtFileName & "") = 0 Then
MsgBox "Please Select a CSV File Before Proceeding"
Me.cmdSelect.SetFocus
Exit Sub
End If
DoCmd.TransferText acImportDelim, "CSVImport", "tblUsage", Me.txtFileName, True
DoCmd.RunSQL ("UPDATE tblUsage SET [Report Date] = #" & ReportDate & "# WHERE [Report Date] IS NULL")
End Sub
However, before I can perform the import, I need to have this done to the CSV file:
1. Open the CSV
2. Walk through each row (starting with row 2)
a. with column D (originally in minutes)
I. if value < 60, do no operations on the figure, and append "Mins" label after it
II. if value > 60 and < 1440, divide it by 60 to 1 decimal, and append "Hrs" label after it
III. if value > 1440, divide it by 1440 to 1 decimal, and append "Days" label after it
b. with columns E, F, and G (originally in bytes)
I. if value < 1,024, do no operations on the figure, and append "Bytes" label after it
II. if value > 1,024 and < 1,048,576, divide it by 1024 to 1 decimal, and then append "KB" label after it
III. if value > 1,048,576 and < 1,073,741,824, divide it by 1,048,576 to 1 decimal place, and then append "MB" label after it
IV. if value > 1,073,741.824, divide it by 1,073,741,824 to 1 decimal place, and then append "GB" label after it
3. Save the file
4. Close the file
Being fairly brand new to VB, I can't seem to figure out how to open a file like this, and make alterations to it. Does anyone have any suggestions on this?
Thanks for any help you guys can provide