Solved

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

Posted on 2001-06-13
8
166 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

895 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

15 Experts available now in Live!

Get 1:1 Help Now