Solved

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

Posted on 2001-06-13
8
168 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

821 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