Solved

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

Posted on 2001-06-13
8
165 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
Comment Utility
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
Comment Utility
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
Comment Utility

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
 

Author Comment

by:Ned_Kelly
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 18

Expert Comment

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

Expert Comment

by:Moondancer
Comment Utility
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
Comment Utility
Thankyou to everybody for there input.
I have accepted beckingh as the answer.
Ned
0
 
LVL 1

Expert Comment

by:Moondancer
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now