Solved

Saving a file with the 'Date and Time' as the file name.

Posted on 2001-06-13
8
167 Views
Last Modified: 2010-05-02
Hi folks, back again.
When I press the cmdEnter in the transaction form I want it to save a text file with the 'Date and Time' as the name of the file, I have tried a range of different code but have not been able to get it to work.
I need to keep a copy of the Transaction as a separate file for every transaction.
The other thing is when it writes to the file it writes the same record thirty times instead of one, as you can see I've a lot to learn.

Private Sub cmdEnter_Click()
Dim strFilename As String
Dim intUserResponse As Integer, intAccNum As Integer, FileName As String
Dim intNew As Integer, i As Integer, intDay As Integer, intMo As Integer, intYr As Integer
Dim udtCredit As CreditStruc, intBal As Integer, NewName As Date



dlgCom.InitDir = "A:\NewName"
dlgCom.FileName = "NewName"

If intUserResponse = vbCancel Then
dlgCom.CancelError = True
End If
dlgCom.Filter = "Text Files(*.txt)|*.txt"
dlgCom.ShowSave
mskAccNum.Text = Val(mskAccNum.Text + 1)
i = FreeFile
Close #i
Open dlgCom.FileName For Output As #i

For intNew = 1 To 30
Write #i, mskAccNum, txtLast, _
mskDeposit, mskWithdrawal, lblDate
Next
Close #i
errHandler:


intBal = frmCredit.mskBalance.Text
Open "A:\Data.dat" For Random As #1 Len = Len(udtCredit)
If mskDeposit.Text <> "" Then
intBal = Val(intBal + mskDeposit.Text)
udtCredit.curBalance = intBal
i = Val(mskAccNum.Text)
Put #1, i, udtCredit
Else
intBal = Val(intBal - mskWithdrawal.Text)
Put #1, i, udtCredit
End If
Close #1
Call ClearFields
mskAccNum.SelStart = 0
mskAccNum.SelLength = Len(mskAccNum.Text)
mskAccNum.SetFocus

End Sub

Thanks for your help.
Ned
0
Comment
Question by:Ned_Kelly
8 Comments
 
LVL 4

Accepted Solution

by:
beckingh earned 50 total points
ID: 6186602
Maybe I'm blind but I don't see where you are trying to create the date and time for the filename.

To create a filename in this format, try:

Dim lsFileName as string

lsFileName = Format(now(), "MMDDYYYY HHMMSS")
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 6186672
For intNew = 1 To 30
Write #i, mskAccNum, txtLast, _
mskDeposit, mskWithdrawal, lblDate
Next
Close #i

The above code writes the current record 30 times.  If there are 30 records you need to add code to get the next record of information.  If there is only 1 record or transaction then you only need the write statement.


dlgCom.FileName = "NewName"

The above statement sets the filename to NewName

Try something like

dlgCom.FileName = format(Now,"YYYYMMDD HHMMSS")

the string in the format call is how you want the date time formatted.  You will want to look in help under format to get the format string you want to use.

good luck
mlmcc
0
 

Expert Comment

by:sureshpodaralla
ID: 6187306

Try this one

For intNew = 1 To 30
  Open dlgCom.FileName For Append As #i
  Write #i, mskAccNum, txtLast, _
  mskDeposit, mskWithdrawal, lblDate
  Close #i
Next



suresh podaralla
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:Ned_Kelly
ID: 6190775
Hi Folks, thanks for the info.
You have fixed both problems in a flash, many thanks again.
Is it possible to accept two answers, and share the points.
Regards Ned
0
 
LVL 18

Expert Comment

by:deighton
ID: 6191866
I believe you need to contact community support to do that
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6198003
Good morning.  I have reduced the points for this question to 50, returning the other 50 points to you, Ned.  To complete this transaction as you wish, you can accept one expert's comments here to grade and close, and post a new question within this topic area for the other 50 points.  Please include this link and in the subject of the new question say "Points for __expert name __", in comments, this link.  

 http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20134652

That expert will then comment or propose an answer there for you to transfer the points by grading and closing that one.  Let me know if you have questions.

Moondancer
Community Support Moderator @ Experts Exchange.
0
 

Author Comment

by:Ned_Kelly
ID: 6198097
Thankyou to everybody for there input.
I have accepted beckingh as the answer.
Ned
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6198355
sureshpodaralla, please post a comment in the question below which Ned created for your contribution here in this point split.

http://www.experts-exchange.com/jsp/qShow.jsp?qid=20136647

Moondancer
Community Support Moderator @ Experts Exchange
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question