Help to import text file of multiple formats (1 Viewer)

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:45
Joined
May 21, 2018
Messages
8,525
This one is so different from the others that you cannot code it the same way. You would need to do something similar to your initial request and hardwire the code for this report. The exceptions and warnings need to go in a separate table exactly like tblReasons except the FK would be a serial_ID. In the code if it is a VR report it calls it own routine and not the generic routine used on the other reports. I will take a look tomorrow.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:45
Joined
May 21, 2018
Messages
8,525
This version has a separate module for the VR report. It pushes the values into 3 VR tables linked by zone_code and serial_ID. The code works but it is super confusing with a lot of if thens and loops. You probably want to make the form similar to the original MOM code where you have two tables.
 

Attachments

  • Read Multiple Reports_V10.accdb
    1.1 MB · Views: 82

lookforsmt

Registered User.
Local time
Today, 10:45
Joined
Dec 26, 2011
Messages
672
Hi! MajP, Apologies, couldnt respond to you earlier.
Thank you for the code, i have amended the names as per my text file and tried to upload the data. Got the following run-time error '9' Subscript out of rang

After i upload, only 11 records get uploaded before showing the error and highlights in module ImportVR
SQL = Split(tempArray(2), " " ) (1)

The text file has more than 200+ records.
tblVR & tbl_Reasons has displayed correct details but it only displays 11 records in each table.
tblVR_Transactions has also displayed 11 records but there is duplicate of amount picked in "Const" field.
Pls refer to attached snapshot. i tried to check the spacing in the text files and i dont see any difference.

The field name "Const" seems to be the issue, but i might be wrong.
 

Attachments

  • VR_Error1.jpg
    VR_Error1.jpg
    114.4 KB · Views: 81

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:45
Joined
May 21, 2018
Messages
8,525
Surround the code as follows
Code:
  If UBound(Split(tempArray(2), " ")) = 1 Then
      SOL = Split(tempArray(2), " ")(1)
  End If

This will keep that error from happening, but does not explain why it is happening. You need to look at that line where it is failing and see what is different.
YTD 1203
 

lookforsmt

Registered User.
Local time
Today, 10:45
Joined
Dec 26, 2011
Messages
672
HI! MajP, now it gives me another run-time error 9, Subscript out of range.
The error has moved to " AvlBal = tempArray(0)
i am not able to identify the reason
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:45
Joined
May 21, 2018
Messages
8,525
In the example you have two data lines. So it finds and reads the first and then moves to the next line. My guess is that there is some line possibly blank between them. That would cause it. Can you look for that. See sample lines A and B for something in between.
 

Attachments

  • VR2 Sample 3.txt
    1.1 KB · Views: 95

lookforsmt

Registered User.
Local time
Today, 10:45
Joined
Dec 26, 2011
Messages
672
Hi I have checked the line A as you mentioned.
If I keep my cursor after Acct Name and hit right key on keyboard. It moves to next row exactly where you placed the B.
The second example is also another instance which in my text is on Srl No 9. Between the A and B there us a row space after the ------- dash and then B follows.
But surprisingly as mentioned earlier it captures 11 self no data.
I hope I have explained you well enough

The error on temp(0) subscript out of range
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:45
Joined
May 21, 2018
Messages
8,525
Any chance you can extract the sheets where it fails and send them? I would need to see how the format is different. Without seeing the "exceptions" it is hard to come up with a strategy. The rule currently is that it finds a dataline then move down a line, but that does not seem to always be the case. I need to see cases when it does not.
 

lookforsmt

Registered User.
Local time
Today, 10:45
Joined
Dec 26, 2011
Messages
672
Thanks MajP, i will try if i can send this across or atleast try to replicate something close.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:45
Joined
May 21, 2018
Messages
8,525
Try this it is a little more robust. In the 'Datalines section of code wrap the Line Input with a loop
Code:
Debug.Print SerialNo & " " & AcctNo & " " & CRN & " " & SOL & " " & AcctName
        'Move to next line
[COLOR="Red"][B] 
       Do
          Line Input #intFile, strIn
        Loop Until IsDataLine(strIn)
[/B][/COLOR]        tempArray = GetCleanArray(strIn)
 

lookforsmt

Registered User.
Local time
Today, 10:45
Joined
Dec 26, 2011
Messages
672
i have updated the code in between the lines. I does not give me any run-time error. It takes time to read the entire doc close to a minute. But does not update any row in any of the 3 tables.

i have attached updated txt file. I realized there is no tab space between any words. it is always with space bar.
hope this is close to real text file
 

Attachments

  • VR2 Sample 3New.txt
    6.1 KB · Views: 82

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:45
Joined
May 21, 2018
Messages
8,525
You may have made a mistake somewhere which put it into a loop. My version seems to read fine. I did not get any errors, but I did not fully verify the all the data. Try this.
 

Attachments

  • Read Multiple Reports_V11.accdb
    1 MB · Views: 96

lookforsmt

Registered User.
Local time
Today, 10:45
Joined
Dec 26, 2011
Messages
672
Thanks MajP, i was trying to check different ways to avoid the loop, possibly may have messed with the code. I will test the updated txt file with the v11 DB on my office network and update you by coming Thr or Fri.
 

Users who are viewing this thread

Top Bottom