UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Message box with contents of a text file    
 
   
BGAccess
post Jul 15 2008, 09:05 AM
Post #1

UtterAccess Guru
Posts: 673
From: Northwest Ohio



Hello all. I have a comma delimited file named poskip.csv. I would like to read this file and put the contents into a message box, but am not sure of the best way to do this. My file would look like the following:

1, 4, 7, 25

and I would like to create a message box that says "The following orders could not be processed at this time: PO 1, PO 4, PO 7, and PO 25." Do I import this file into a temporary table, and then loop through the records to come up with this, or is there an easy way to do this using only VBA?

Thanks for any help,
Kevin
Go to the top of the page
 
+
Doug Steele
post Jul 15 2008, 09:28 AM
Post #2

UtterAccess VIP
Posts: 17,613
From: Don Mills, ON (Canada)



CODE
Dim intFile As Integer
Dim strBuffer As String
Dim strFile As String
  
  strFile = "C:\Folder\poskip.csv"
  intFile = FreeFile
  
  strBuffer = Space(FileLen(strFile))
  
  Open strFile For Binary Access Read As intFile
  Get #intFile, , strBuffer
  Close #intFile
  
[color="green"]' At this point, strBuffer will contain the entire contents of the file.[/color]

Go to the top of the page
 
+
doctor9
post Jul 15 2008, 09:47 AM
Post #3

UtterAccess VIP
Posts: 9,266
From: Wisconsin



Kevin,

I would read the Access help on the Split Function (to split the comma-delimited text into an array of values).

With this tool, you can split the comma-delimited data into an array of values. From there, you can assemble the string to be displayed in the textbox by looping through the array of values.

Hope this helps,

Dennis
Go to the top of the page
 
+
BGAccess
post Jul 15 2008, 10:43 AM
Post #4

UtterAccess Guru
Posts: 673
From: Northwest Ohio



Thanks to both of you. I was able to get the contents of the file using Doug's suggestion, and then was able to split it into an array using the recommendation from Dennis so I could customize the message box a little bit more. When I was researching the Split function I came across a different way of getting the file contents into a string. Is there any benefit of using the following instead of the technique Doug gave?

QUOTE
Dim intFile As Integer
Dim strBuffer As String
Dim strFile As String

strFile = "C:\Folder\poskip.csv"
intFile = FreeFile

Open strFile For Input As #intFile
strBuffer = Input(LOF(intFile), #intFile)
Close #intFile


It seems that it accomplishes the same thing. Is one better, or more reliable than the other?

Thanks for the help,
Kevin
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 19th May 2013 - 06:18 PM