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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open a file read it AND write back at next line? 3

Status
Not open for further replies.

PWD

Technical User
Jul 12, 2002
823
GB
Is it possible to open a file and insert data and re-save it? I have the following
Code:
 Open Filename For Input Access Read As #1
. Then I
Code:
Do Until EOF(1)
    Line Input #1
then loop through looking for a specific line, examine it & compare that part with an SQL View. So far, so good. What I want to be able to do is, where there's a match between the line and the SQL View, be able to write a field from the View back into the file at the next line (which is always blank at the moment). How can I write this data (that I've got working with my code OK) back to the file & save it?

Many thanks,
Des.
 
Des,

1) I think Mr strongm is suggesting you discard the previously suggested code completely and replace it with his, I suggest you stick with him because it is likely you will end up with an inovative and efficient solution.

2) If you stick with the existing code note Andrzejek's example of 13 Jul 09 8:42

rs.Filter = " Part = '" & PartNumber & "'"

Select Case rs.RecordCount
Case 1
FSDesc = rs.Fields("FSC Desc").Value
Case 0
FSDesc = "No Desc for " & PartNumber
Case Else
FSDesc = "More than one Desc for " & PartNumber
End Select

Did you try testing rs.RecordCount in this manner?
 
Hi Hugh. I see what you're saying, but I'm not sure I have the time, at the moment, to start from scratch as VB is only a part of what I do; I'm also part of a Helpdesk looking after all our users' needs etc.

I looked at what Andrzejek has done but if there's no match I don't need anything to be output as this would be added to invoice - so no match = no output. There will only be one match in the View.
 
>so no match = no output

So did you try;

If rs.RecordCount=1 then

in place of your;

If Not rs.EOF And Not rs.BOF Then
 
>start from scratch

I'm not suggesting that. However, I am suggesting that you can replace the code you have shown here with my code. Unless, of course, what you have shown us isn't the actual code at all.
 
Hi Hugh. Yup. Totally didn't work. [surprise]

Hi strongm, I thought you weren't suggesting a complete restart, but then I thought I must have missunderstood what you'd meant. [ponder]

Like I said I'll try to fit in the re-coding around everything else. I really appreciate your input and will post what I get to work - when I get it to work.

Des.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top