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

create new text file every time 1

Status
Not open for further replies.

clientuser

Programmer
Apr 18, 2001
296
US
I know how to create a text file and how to append to it and read from it, but how do i create a new text file for each record i save?

There is a form in my project that allows users to save information and it also saves a text file out to the apps location. however, it only saves one text file, but i would like for it to create a new text file for each new entry.

that leaves me stuck........ any suggestions?
 
also to add to this, how do you handle date text in the name of the file when its saved? i have:

Code:
strTarget = App.Path & ("\RX" & Date & ".VetSch")

because the date is formated as: 1/1/2004 the system thinks its a path indicator and gives "path not found" error

i really need the date in the name of the file when its saved as well.
 

what about the file naming issue?? do u want to create new files with random names or u have some scheme for the naming??? every file has a unique name with in the same folder.

u can try a combination of GetTempFileName() API with either vb's native file i/o functions or u can use this API with FSO, if file names r not of importance.
 
oops, i think u hit the ubmit button before me :)

date issue: try Format(Date, "yyyymmdd")
 
the file names when they are saved will have a similar pattern:

RX-10/1/2004.VetSch

The date will be a string that i pull from one of the fields in the form.

so each time the user creates a new record, a new text file is create for that record.

so depending on how many records they create, the folder would show something like:

RX-10/2/2004.VetSch
RX-11/5/2004.VetSch
RX-11/28/2004.VetSch

etc.........



 

two things r here now:
1... u cannot have / or \ in filenames.
2... what about the situation when a user creates more than 1 record per day??? obviously a filename conflict will occur. better to use date n time both in ur filenames.
 
i have decided to not use the date in the file name itself, it will create to many problems.

my other question is, how do i create a new file each and every time the user creates a new record?



 
sorry... pressed submit button by mistak. continue from my last post...

try this

Code:
strTarget = App.Path & ("\RX" & Format(Now(), "yyyymmddhhmmss") & ".VetSch")

hope it will help u.
 
thats perfect! i was heading towards the now format just as i got your reply..

 
thank u for the star, clientuser :)

well, there r so many ways to create new file with every new record. e.g. (in pseudo code)

Code:
Public Sub CreateNewRecord()
   'your code to create new record 
   'and updatingg DB goes here
   'after successfully updating DB
   'follow these steps
   if DB updated succefully then
      create and store the new file name, using methods posted in previous posts, in a variable
      get free file number using Free() function
      open new file in sequential mode for writing
      write the data i.e. your record, to file
      close the file using Close(filenumber) function
   else
      do what ever you want in case new record not created
   end if
End Sub

i assume you are using native file i/o function i.e. Open, Close, Free, Input etc.

you can use FSO instead of these functions.
just call this Sub when ever user create a new record and if user is successful a new file will be created every time with new reccord.

i'm sorry i cannot write exact code cuz VB is not available to me right now.

good luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top