Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Visual Basic





See Related Forum Messages: Follow the Links Below to View Complete Thread

Filename As Date And Time
I want to save something to a file and want to name the file as the present date and time.
I know i can make use of 'NOW' in VB.........but how should i go abt doing it?? Or any other method to do so??

Trying To Make A Filename Up From The Date And Time , Help Needed Please
Hi
I am copying a file into an archive area and when I copy the file I want to change its name from whatever to the current date and time ie
copy the file plantdata.txt to 2002215_1056.txt

this works until the time is say 16:04 , then the file is saved as
2002215_164.
this will be a mess if it is 2 minutes past 9 in the morning as I think it will display it as 92 , how can I format it to be 0902 etc.

here is my code , its only one line , could someone show me how to do this , code would be great !

FileCopy File$, ReadIniFile("directories", "copyfile") & Year(Date) & Month(Date) & Day(Date) & "_" & Hour(Time) & Minute(Time) & ".txt"

Copying And Renaming A File With The Date/time In The Filename
Hi there,

I've never done much with VB as far as moving files aroudn and such and am hoping someone cna whip me up what I think wuld be a very simple little program.

All it would do would be every hour, take a file from a particular folder, copy it to a different folder, and rename it and add the date/time onto the filename somehow.
So a file called Database.mdb would get changed to database 031420021100 for March 14th, 2002 at 11:00. It doesn't have to be that format, just an example.

Can someone give me the couple lines I'm guessing it would take to do that?

THanks,
-Mike

How To Save A Text File With Date And Time As Filename
Hi, Plz help me out.

How to save a text file with date and time as filename.

My code is:
dt = Date
tt = Time
 intFile = FreeFile()
        Open App.Path & "" & dt & tt &.txt" For Output As #intFile
        Write #intFile, sometext
        Close #intFile

But it is not working.

Thanks in advance

Date & Time Values In Date And String Format Differ
The program (debug) output below lists the last modification time of two files. File 1 is stored on a NTFS medium, file 2 sits on a FAT medium.

In order to be able to compare these dates, I need to round the odd seconds of the NTFS file up (FAT files have only even second values).

The lines after the file headers show the date & time value before and after the rounding, in date, double precision and string format.

file 1 (NTFS)
= 2005-07-12 08:57:09 = 38545,3730208333 = 2005-07-12 08:57:09
after rounding up
= 2005-07-12 08:57:10 = 38545,3730324074 = 2005-07-12 08:57:10

file 2 (FAT)
= 2005-07-12 08:57:10 = 38545,3730324074 = 2005-07-12 08:57:10

The strange thing is that when comparing these values, they appear to be different (!) both in date and double data format, not in string format.

2005-07-12 08:57:10 > 2005-07-12 08:57:10 (date format)
38545,3730324074 > 38545,3730324074 (double precision format)
2005-07-12 08:57:10 = 2005-07-12 08:57:10 (string format)

Any idea where this difference comes from?

Rounding up was done with DateAdd.

VB version 6, on XP.
Boiled down code has been attached.

Convert Time Ticks Into Date Time/string Format
I have time ticks and wanted to convert into string or date time format in visual basic 6.

Thanks in advance.

Concatenate A String
Hi there,

I'm trying to generate an email where values are passed from an excel spreadsheet. My code is working, but the values are not coming in from the sheet.

I think I'm not concatenating the string/output properly. Can someone advise what I'm doing wrong?


Code:
Sub copy_into()
Dim user As String
Dim date_received As String
Dim assigned_staff As String
Dim email As String
Dim sender As String
Dim mgr_email As String
Set olApp = CreateObject("Outlook.Application")
Set olMail = olApp.CreateItem(olMailItem)

Sheet1.Select

user = Sheet1.Range("a3").Value
date_received = Sheet1.Range("b3").Value
assigned_staff = Sheet1.Range("d3").Value
email = "email@anywhere.com"
mgr_email = Sheet1.Range("f3").Value
sender = Sheet1.Range("e3").Value

With olMail
.To = email
.Display
.Subject = "Automated Response/Testing Excel Automated Email Response."
.Body = "FAO: " & Sheet1.Range("e3").Value & "This is an automated response to your query regarding" & _
Sheet1.Range("f3").Value & "This task has been assigned to: " & _
Sheet1.Range("d3").Value & "Your job number is: " & Sheet1.Range("a3").Value & _
"Please quote this reference number when making any further inquiries."
.Send

End With

MsgBox (" your Email was sent To this user: " & day_phone)

End Sub


I've tried the output section like this also:


Code:
With olMail
.To = email
.Display
.Subject = "Automated Response/Testing Excel Automated Email Response."
.Body = "FAO: " & sender & _
"This is an automated response to your query regarding" & _
mgr_email & "This task has been assigned to: " & assigned_staff & _
"Your job number is: " & user & _
"Please quote this reference number when making any further inquiries."
.Send

but that doesn't work either.

Any help would be greatly appreciated!

Thanks,

q_jd.

How To Concatenate String?
example: BALAGAN, MARIBETH PINEDA

how can i get the BALAGAN in Text1.Text, MARIBETH in Text2.text, and PINEDA in Text3.Text.

thanks in advance

How To Concatenate String To Memo
Hello all,

I am desparately trying to concat a string field to a memo field and output the result into a text file or use it in a query. The problem is that, whatever I do, the result of the concatenation is cut off after 255 characters.

Example:
Table 1:
Title: string - 128 chars
Description: memo

Query 1:
TitleDescription: [Title] & " - " & [Description]

Output:
The famous dictionary of computer terms - This book covers a wide range of ......... and expl
Access for beginners - An easy introduction into the world of databases ....... with many illustr

The output always cuts off. If I try the same in a module and write some code using Print #1 or Put #1 or something like that, the result is still cut off. I tried to use GetChunk(offset, size) but that always returned the beginning of the memo field and not chunks from inside the memo field.

Here is my code:

public Function OutputToActinicCatalog()

DoCmd.Hourglass true

' Open query "Output to Actinic Catalog"
Dim DB as Database
Dim Records as Recordset

set DB = CurrentDb

' get contacts
set Records = DB.OpenRecordset("Output to Actinic Catalog")

' Create CSV file
Open CurrentProject.Path & "Output to Actinic Catalog.txt" for Output Access Write as #1

Dim Output, I as Long
Dim Newline as string, Quote as string, Comma as string

Newline = Chr$(13) & Chr$(10)
Quote = """"
Comma = ","

Output = ""

While Not Records.EOF

' Write memo field to file
for I = 0 to Records.Fields("Description").FieldSize - 1 step 255
Output = Records!Description.GetChunk(I, 255) ' This ALWAYS returns the FIRST(!!!) 255 characters - why?
print #1, Output
next I

Records.MoveNext
Wend

Records.Close

Close #1

DoCmd.Hourglass false

End Function





Any help would be much appreciated.

Ta,
Oliver.

Hope this helps?
Oliver

Efficiency Of Concatenate Long String
I know that with using the & to concatenate a very long string in looping will take quite some long time.


Is there any effiency for me to do the concatenate of long string instead of uising '&'?


Thanx,
Ethan

Concatenate Byte Array With String - Why?
I had some problems doing this in vb6.

Dim output() As Byte

output = (call_some_function_that_returns_byte_array)

Dim Size As Integer
Size = Len(SomeTextBox.Text)

Dim str As String

Dim i As Integer

For i = 0 To Size - 1 Step 1
str = str + output(i) 'compile error,
Next

Error:

Run time error '13'
Type mismatch

Any idea? Thanks. I want to store each value within the byte(i) array and dump into a string and later display in a label.

Thanks.

Concatenate Each Char In String To Make It 16-bit?
Hello all,

I am trying to write a VB version of a PHP script to convert each character in a string into a specific base64 format. The PHP script can be seen here:

http://www.mikemarsbooks.co.uk/Turbo...tation.php.txt

I have converted everything successfully apart from the very last function, which takes each character and concatenates it with the chr(0) character (null character) to make it into a 16-bit character. This is then converted into the base64 format. I can do the base64 bit but am having real problems with the concatenation bit. Please can someone help? Thanks in advance.

How To Concatenate Arrays Into A Common String?
I am trying to concatenate an integer from an array into a text string using the Cstr command. The compiler keeps highlighting the Cstr expression stating that it is expecting a sub or function when it sees the () in it, or that the date(0) expression is not defined.

Dim date(3) as integer on form1.

label1 = "...xxx... " & Format$(now, "mmmm") & Cstr(date(0)) & " ..xxx..." in a command button procedure with the button in a SStab1 tab frame on form1.

Tried using a sub and Function for it but the compiler didn't like that either.
Any suggestions on how to construst text strings using concatenated intergers and other string phrases would be greatly appreciated.

______________________

I used "date" just as a shorthand for the entire name.

I tried the Option Explicit suggestion with the same result - "intMdate(0)" highilighted and "Sub or Function not defined"

I mistyped the CStr command in my query. The command in the code is CStr.

I tried VBA.CStr(intMdate(0)) with the same result.

Thanks for the suggestions. Any other ideas?

Data Reports, String Concatenate
Can anyone help,

I need to concatenate a string onto a field on my datareport.

e.g.

In MS Access 97 you would simple put the following in the control source of the control.

="Total " & [Total Field]

How do I do this in a data report for VB6.

Thank's for any help,

Chris

How To Pass String To Concatenate Routine.
First, let me say I am not a skilled programmer!

I am trying to write some VB6 code that creates a string with the files names in a directory and then passes it to a concatenate routine to create one text file containing the contents of each file in the directory.

I am using the “ListFiles” and “ListFilesPriv” functions to create a variable of the file names and the “ConcatenateFiles” routine to create the new text file with the contents of each file in the directory.

My problem is I cannot seem to pass the string of file names created with “ListFiles” and “ListFilesPriv” functions to the “ConcatenateFiles” routine! I can manually type the file names into the code and it works fine, but if I try and pass a string containing all the file names to the “ConcatenateFiles” routine, it does not work! It is driving me crazy!

Below is a copy of the test code I am trying to get working (I know it is messy, I will clean it up after I get it working)

Can anyone tell me why I can the “ConcatenateFiles” routine to work if I manually enter the file names as follows?
ConcatenateFiles "K:DSN-QAVB ProjectsKMM S-C INTERFACE v2.0Databasedata.txt", "", "K:DSN-QAVB ProjectsKMM S-C INTERFACE v2.0DatabaseLog3-02-2007_16-57-03_KM32G02003AEE_00D0E09448DC.csv", "K:DSN-QAVB ProjectsKMM S-C INTERFACE v2.0DatabaseLog3-06-2007_10-01-09_KM32G030004FA_00D0E09214C1.csv"

However, not if I try passing the file names with a string like the following.
ConcatenateFiles "K:DSN-QAVB ProjectsKMM S-C INTERFACE v2.0Databasedata.txt", "", temp4
Thanks in advance for any help or advice you can give me!

sjh
-----------------------------------------------------------------------------------------

Dim temp
Dim temp1
Dim temp2
Dim temp3
Dim temp4
Dim temp5$
Dim temp6
Dim quote$
Dim comma$

' list all the files in a directory
' if NESTEDDIRS = True it lists a whole directory tree
'
' returns a 1-based array containing all the listed files

Function ListFiles(ByVal Path As String, Optional ByVal NestedDirs As Boolean) _
As String()
Dim fso As New Scripting.FileSystemObject
Dim fld As Scripting.Folder
Dim fileList As String

' get the starting folder
Set fld = fso.GetFolder(Path)
' let the private subroutine do all the work
fileList = ListFilesPriv(fld, NestedDirs)
' convert to a string array
' (the first element will be a null string)
ListFiles = Split(fileList, ",")

End Function

' private procedure that returns a file list
' as a comma-delimited list of files

Function ListFilesPriv(ByVal fld As Scripting.Folder, _
ByVal NestedDirs As Boolean) As String
Dim fil As Scripting.File
Dim subfld As Scripting.Folder

' list all the files in this directory
For Each fil In fld.Files
ListFilesPriv = ListFilesPriv & "," & fil.Path
Next

' if requested, search also subdirectories
If NestedDirs Then
For Each subfld In fld.SubFolders
ListFilesPriv = ListFilesPriv & ListFilesPriv(subfld, NestedDirs)
Next
End If

End Function

Private Sub Command1_Click()
TestGetAllFiles
temp = Len(temp2)
temp3 = temp - 4
temp1 = Left(temp2, temp3)
temp4 = Trim(temp1)
temp5$ = "K:DSN-QAVB ProjectsKMM S-C INTERFACE v2.0Databasedata.txt"
temp6 = ""
Debug.Print "K:DSN-QAVB ProjectsKMM S-C INTERFACE v2.0Databasedata.txt", "", "K:DSN-QAVB ProjectsKMM S-C INTERFACE v2.0DatabaseLog3-02-2007_16-57-03_KM32G02003AEE_00D0E09448DC.csv", "K:DSN-QAVB ProjectsKMM S-C INTERFACE v2.0DatabaseLog3-06-2007_10-01-09_KM32G030004FA_00D0E09214C1.csv"
ConcatenateFiles "K:DSN-QAVB ProjectsKMM S-C INTERFACE v2.0Databasedata.txt", "", temp4
End Sub


Sub TestGetAllFiles()
Dim varFileArray As Variant
Dim lngI As Long
Dim strDirName As String

Const NO_FILES_IN_DIR As Long = 9
Const INVALID_DIR As Long = 13

On Error GoTo Test_Err

strDirName = "K:DSN-QAVB ProjectsKMM S-C INTERFACE v2.0DatabaseLog"
varFileArray = ListFiles(strDirName)
For lngI = 1 To UBound(varFileArray)
Debug.Print varFileArray(lngI) & ", "
temp2 = temp2 + varFileArray(lngI) + ", "
Next lngI

Test_Err:
Select Case Err.Number
Case NO_FILES_IN_DIR
MsgBox "The directory named '" & strDirName _
& "' contains no files."
Case INVALID_DIR
MsgBox "'" & strDirName & "' is not a valid directory."
Case 0
Case Else
MsgBox "Error #" & Err.Number & " - " & Err.Description
End Select
End Sub


' Concatenate a variable number of text files into a single result file
'
' Params:
' - ResultFile: the complete path of the result file you want to create
' - Separator: a string that is written when a file is added to the result
' file.
' Note: this string can contain the #FilePath# tag that will be replaced
' with the path of the file being added
' - SourceFiles: a sequence of files whose content will be concatenated
'
' Example:
' ConcatenateFiles "D:
es.txt", "------ NEW FILE: #FilePath# ------",
' "D:1.txt", "D:2.txt", "D:3.txt"


Private Sub ConcatenateFiles(ByVal ResultFile As String, _
ByVal Separator As String, ParamArray SourceFiles() As Variant)

Dim fso As New FileSystemObject
Dim fsSourceStream As TextStream
Dim fsResStream As TextStream
Dim sSeparator As String
Dim i As Integer

On Error Resume Next

' create a new file
Set fsResStream = fso.OpenTextFile(ResultFile, ForWriting, True)

' for each source file in the input array
For i = 0 To UBound(SourceFiles)
' add the separator first (replacing the special tag for the file path)
sSeparator = Replace(Separator, "#FilePath#", SourceFiles(i))
'sSeparator = Replace(Separator, "", SourceFiles(i))
'fsResStream.Write sSeparator & vbCrLf
fsResStream.Write sSeparator
' open the file in read mode
Set fsSourceStream = fso.OpenTextFile(SourceFiles(i), ForReading)
' add its content + a blank line to the result file
'fsResStream.Write fsSourceStream.ReadAll & vbCrLf
fsResStream.Write fsSourceStream.ReadAll
' close this source file
fsSourceStream.Close
Next i

fsResStream.Close
End Sub

Private Sub Form_Load()
quote$ = Chr(34)
comma$ = Chr(44)
End Sub

Converting A String To A Date/Time
I have in a string "10:40 AM".
I would like to covert the "10:40 AM" to a Date/Time or double.

Reason:

To get the DateDiff between "10:40 AM" and Now/Time.


Thanks in advance.

Error Date/Time Vs. String
I try with a sql-string but get this errormessage :
"Run time error '-2147217913(80040e07)':
"Data type mismatch in criteria expression"

The field Jobber!UtforesDato is a Date/Time field in Access,
and have example 30.05.2005 in the record if I look in Access.

Why I get the error ?
If I try to change the field properties to String instead of Date/Time in Access
everything work well.......


dagensdato = Date

sql = "Select * From Jobber Where Jobber!UtforesDato = '" & dagensdato & "'"

Date/Time/String Manipulation
Sorry if I've missed it, but I had a quick search for similar problems and didn't turn anything up.

I have a GUI with two text fields where the user enters a date into one and the time into another. I then need to concatenate the two strings together into a date variable.


VB Code:
Dim datFromDate As Date datFromDate = CDate(txtFromDate.Text) & CDate(txtFromTime.Text)


Any ideas, because this just throws up a Type Mismatch error.

Converting String To DATE & TIME
In VB there are many functions available to convert strings to date for eg.

DateValue, cdate . If these functions were fed in with a string containing date and time in the format "dd.mm.yyyy hh:mm:ss" These functions convieniently dropout the time part and convert the date only. for example

? datevalue("01.12.2001 13:50:12")
01.12.2001 ' Drops pot the time

? Cdate("01.12.2001 13:50:12")
01.12.2001 13:50:12 ' this one doesnt drop out the time but doesnt have any regard for it I mean

Cdate("01.12.2001 13:50:12") = Cdate("01.12.2001 21:50:12") is the same. I hope u understand what i mean.

Can anyone tell me some function which actually regards a difference in the time too ?

Regards

Nikhil

How Do You Change Date / Time With A String?
I'm making a program that involves letting the user change the time manually. They enter the date or time in the textbox and press the command button. I can't get this to work because the DATE and TIME use the long format and the textbox uses strings. I get an error like
"#9:00:00 PM#" (INVALID FORMAT) or something. I believe it is because of the quotes ("") due to the textbox strings. How do you convert long to string, or fix this problem? Thanks.

Input Date And Time As A Unique String
I'm using an inputbox to input a date:

VB Code:
Dim dt as date dt = CDate(Inputbox("Input a date"))

What I'd like to know is what format I should use to include the time in the variable dt.
If I just input the date as, say, 9-6-1992 it works but when I've tried 9-6-1992 19:33:46 I've got an error.

Adding 2 Days To Date Time String
Is there an easy way to add 2 days to the datetime string that I'm using below?

Code:Dim CurrentTime As String = Format(Now, "yyyyMMddHHmmss")

Part2: How To Convert String To Date/time) -reverse
RobDog888, thank you for reply the part one.

This is what I did:

VB Code:
Private Sub Form_Load()   Dim strTime As String      strTime = "0247"   strTime = Left(strTime, 2) & ":" & Right(strTime, 2)   strTime = FormatDateTime(strTime, vbLongTime)   MsgBox strTime   End Sub


Now, the strTime = "2:47:00 A.M."
How to reverse it to its original value, “0247”?

thanks.
vb999

File Information Get Path ,filename,filesize,access Date ,modified Date
This tiny zip file have filename,filepath,fileaccess date,file modified date
if picture file then size of the picture

Thanks guys

bellow code
-------------------------------------------------------------------
Private Const OF_READ = &H0&
Private Declare Function lOpen Lib "kernel32" Alias "_lopen" (ByVal lpPathName As String, ByVal iReadWrite As Long) As Long
Private Declare Function lclose Lib "kernel32" Alias "_lclose" (ByVal hFile As Long) As Long
Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long

Dim lpFSHigh As Long
Private fileN As String
Private fileP As String
Private fileS As Double
Private fileC As String
Private fileA As String
Private fileH As Long
Private fileW As Long
Private fileX As String
Dim fs As Scripting.File
Private Sub Command1_Click()
Call commonDialogCall
Call GetFileS(fileX)
Call FileWHget
Call FileDateGet
Call displayall
End Sub
Public Sub displayall()
Label1.AutoSize = True
Label2.AutoSize = True
Label3.AutoSize = True
Label4.AutoSize = True
Label5.AutoSize = True
Label6.AutoSize = True
Label7.AutoSize = True

Label1.Caption = "File name = " & fileN
Label2.Caption = "File path = " & fileP
Label3.Caption = "File size = " & fileS & " Byte"
Label4.Caption = "File Created = " & fileC
Label5.Caption = "File Accessed = " & fileA
Label6.Caption = "File height = " & fileH
Label7.Caption = "File Widht = " & fileW
End Sub
Public Sub commonDialogCall()
CommonDialog1.Filter = "*.bmp"
CommonDialog1.ShowOpen
fileX = CommonDialog1.FileName
fileN = CommonDialog1.FileTitle
fileP = Left(CommonDialog1.FileName, Len(CommonDialog1.FileName) - (Len(CommonDialog1.FileTitle) + 1))
End Sub
Public Sub GetFileS(FilePath As String)

Dim Pointer As Long, sizeofFile As Long
Pointer = lOpen(FilePath, OF_READ)
'size of the file
sizeofFile = GetFileSize(Pointer, lpFSHigh)
fileS = sizeofFile
lclose Pointer
End Sub
Private Sub FileDateGet()
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(fileX)
fileC = f.DateCreated
fileA = f.DateLastModified
End Sub

Private Sub FileWHget()
Dim pic As Picture
Set pic = LoadPicture(fileX)
fileH = pic.Height
fileW = pic.Width
End Sub

Private Sub Command2_Click()
End
End Sub
---------------------------------

REQ Help: Calculating Elapsed Time From Date/time Began From Date/time Ended
I have four controls, two are Date-Time Pickers set for Date and the last two are text boxes set for Time with the "...If Not IsTime()..." validation.

It is the standard Date and Time problem began, Date and Time problem ended.

I am trying to calculate the elapsed time between these in "" DAYS "" HOURS ""MINUTES.

I coded this in Lotus Notes yet exporting my knowledge to VB is problematic.

Has anyone a code snippet of how to do this in VB - yes, I know about the DateDiff.

Many, MANY thanks!

Date As Filename
Hi,

I've just recently started using and Im trying to create a program that stores orders from customers and i want to store the orders in Dates. Here is the coding i've tried

Open ("H:Computing - VB FilesThe WelcomeOrdersOrder [" & lblDateTime & "].txt") For Append As #2
For l = 0 To LstDishName.ListCount - 1
Write #2, LstDishName.List(l)
Next l
Close #2

The error it gives me is "path not found", ive check it and the directory is there, but it could be ..Order [" & lblDateTime & "].txt".. that causing all the problems.

Any ideas on how i can solve this problem

Thanks

Date With Filename
hey guys...

i have a problem in displaying the date with a file name...

Dim BackupTag As Long
BackupTag = Date

FileCopy App.Path & "db.mdb", App.Path & "BackUpBackup " & BackupTag & ".mdb"

with this I don't get any date attached with the file name...instead i get a weird number after backup...

any help?

Rgds,

Farooq

Add Date To Filename
I'm using the code below to rename an xls and it works fine. The problem I'm facing is the need to add the date to the filename. If I try to add within the quotes then naturally the interpretaion is literal. So I've been trying to work outside of them but I still can't get it to workout.

Dim source As String
Dim destination As String


source = "c:oldworkbook.xls"
destination = "c:
ewworkbook.xls"

Name source As destination

Add Date To FileName
I want to add the Date to the File Name if the user clicks a Check Box. In using the following code, I end up w/ the Date showing up in the "File Name" box in the Save Dialog. The user would have to click at the front of the date and then type in the name (too much effort required )Tried it another way using an "If" "Then" at the Shell statement but that ended up with "Test.REG-12-31-07". I want to have the Date added behind the scenes if possible so it comes out "Test-01-01-07.REG"


VB Code:
If Check1.Value = 1 Then   CommonDialog1.FileName = CommonDialog1.FileName & "-" & Format$(Date, "mm-dd-yy") '<---- Using "strFileName =" at the front just ends up w/ no date.         Label2.Caption = "The current date will be added to the Filename."End If CommonDialog1.ShowSave

How To Check If The Current Date/time Is &gt;15 Mins More Than Another Date/time?
Say you have the date/time stored in a string like so:
"2008-06-05 01:58:30"

How can you check if the current date/time is > the date/time stored in the string + 15 minutes?

Adding A Date To A Filename
Hey Folks

I am currently writing a program that processes a report in excel.
I have been having problems writing code in VB that will allow me to insert the date to the end of the filename. The spreadsheet is called EQ Report. So if the program were run today I would want the filename to be EQ Report (07-Nov-05).

I know how to name the filename, but I am not sure how to format the date so it is not in the 07/11/2005. As you will know backslashes can't be in filenames due to indicating a folder.

I've tried looking at date functions etc and have not really got anywhere with it.

If this is not possible then I would alternatively like to know how to add the month only onto the end of the filename.

Any guidance and tips would be great.

How To Append Date To A Filename
I have a VB app that needs to access a specific file frequently.


Code:
Open "c:
ibbondailylogdailybatchlog-17.txt" For Input As SourceNum


Now the 17 at the end of the filename is the date. And the file name automatically changes daily, appending the date in the end. I am using the above code to open the file to read, but since the name changes daily, I have to change the file name manually in the source code, every day. I know it sounds terribly dumb, but thats how ive been doing it.

Can anyone please tell me how to automatically append the date to the end of the file name?

Get FileName Of Last Modified Date
Dear VBA expert,

I am stuck with this how to get the filename of the LastModifiedDate and input the filename to a cell. I managed to open it from C:Data, copy 2 sheets over but was unable to place the filename in cell IV2. I hope someone can help me on this. Any help is greatly appreciated.


CODESub GetLastModifiedFileName()
Dim fs As FileSearch, ws As Worksheet, i As Long, loc As Long, fdt As Double
Dim wsh As Worksheet
Set fs = Application.FileSearch
    With fs
        .SearchSubFolders = False
        .FileType = msoFileTypeExcelWorkbooks
        .LookIn = "C:Data"
        If .Execute > 0 And .FoundFiles.Count > 0 Then
            loc = 0
                For i = 1 To .FoundFiles.Count
                       If FileDateTime(.FoundFiles(i)) > fdt Then loc = i
                Next i
               Workbooks.Open .FoundFiles(loc)
                Else
            Exit Sub
        End If
    End With
       
    Sheets(Array("Region", "Output")).Select
    Sheets(Array("Region", "Output")).Copy After:=Workbooks("TEMPLATE.xls").Sheets(1)  
    Windows("TEMPLATE.xls").Activate
    Sheets(1).Range("IV3") = Environ("Username")
    Sheets(1).Range("IV4") = Now()
End Sub

Filename With Date Save
Is there a way to save a filename with the current date in the filename?
I would like to keep a generic title in front (or behind) the date extension..
i.e. New File092703.xls or 092703New File.xls or whatever date format I could use.

Thanks

If I'm not back in five minutes... ...Just wait longer!!!!
   -Ace Ventura

How Can I Convert String "0,35" To Date/time ?
How can I convert "0,375" (VarType says it's a string) to date/time ?

You maybe interested how I'v got "0,375" string - it's a value of Excel cell that has format set to "time" and value of "9:00:00".

TimeValue is quite dumb and won't understand integers or string with integer as parameter. Any ideas how I can get time from such value?

Generate Filename With Current Date [VB6]
I want to generate a FileName [string] as “MMDDYY_DReg.xls”
So I need to find a way to generate the MMDDYY of Today (dynamically so it changes each day when the user generates the file name)

Something like:
Dim Filename as String
Filename = DateTime.Today & “_DReg.xls”

Or even better something like (should not make a difference):
Dim Filename as String
Filename = App.Path & "" & DateTime.Today & “_DReg.xls”

Generate Filename With Current Date [VB6]
I want to generate a FileName [string] as “MMDDYY_DReg.xls”
So I need to find a way to generate the MMDDYY of Today (dynamically so it changes each day when the user generates the file name)

Something like:
Dim Filename as String
Filename = DateTime.Today & “_DReg.xls”

Or even better something like (should not make a difference):
Dim Filename as String
Filename = App.Path & "" & DateTime.Today & “_DReg.xls”

Send Attachment With Filename + Date
Can anyone tell me what im doing wrong here?


Code:
Public Sub SendMail()


frmMain.lblStatus.Caption = " Sending Mail..."
Set poSendMail = New clsSendMail
poSendMail.SMTPHost = frmOptions.txtSMTP.Text
poSendMail.From = frmOptions.txtEmailFrom.Text
poSendMail.FromDisplayName = frmOptions.txtDisplayName.Text
poSendMail.Recipient = frmOptions.txtEmailTo.Text
poSendMail.Subject = frmOptions.txtSubject.Text
poSendMail.Attachment = frmOptions.txtZipTo.Text & Format(Now, "dd_mm_yy") & ""
poSendMail.Message = frmOptions.txtMessage.Text
poSendMail.Send
frmMain.lblStatus.Caption = " Message Sent..."
End Sub


When I remove the & Format (Now,.....) part and put the full file name into frmOptions.txtZipTo.text it works fine. But I need it to get a new file name everyday, ie "myFile_12_06_02.zip But tommorow it will be "myfile_13_06_02.zip.

Any suggestions ( is it just the formating of my code???)

Make System Date The Filename
Code:

Private Sub save2_Click()
Dim textbuffer As Long
If Dir(App.Path + "" & DateTime.Date & ".txt") = "" Then
textbuffer = FreeFile
Open (App.Path + "" & DateTime.Date & ".txt") For Output As #textbuffer
Print #textbuffer, MainForm.RTB.Text
Close #textbuffer
Else
textbuffer = FreeFile
Open (App.Path + "" & DateTime.Date & ".txt") For Output As #textbuffer
Print #textbuffer, MainForm.RTB.Text
Close #textbuffer
End If
End Sub


It's a text buffer for a chat...

basically I need the filename to be the current system date, but it won't work how it is...

Any help will be greatly appreciated.

Thankyou.

Display Current Date With Saved Filename
Anyone knows how I can integrate this ---> & Format$(Now, " ddmmmmyy") into my code below in order to display the current date automatically right before the file name of CommonDialog.Filename. I've tried several ways but best I can do is to display curent date as the file extention.


Code:
Private Sub mnuSave_Click()
Dim strForText1 As String
Dim strForText2 As String
Dim fsave As String

CommonDialog.CancelError = True
On Error GoTo ErrorHandler
CommonDialog.InitDir = (App.Path & "")
CommonDialog.DialogTitle = "Save To .TXT"
CommonDialog.Filter = "Text File (*.txt)|*.txt"
CommonDialog.FilterIndex = 1
CommonDialog.Flags = cdlOFNHideReadOnly + cdlOFNOverwritePrompt + cdlOFNPathMustExist + cdlOFNNoChangeDir
CommonDialog.DefaultExt = ".txt"
CommonDialog.ShowSave

Dim FileName As String
FileName = CommonDialog.FileName
fsave = FreeFile()
Open CommonDialog.FileName For Output As fsave
Write #fsave, strForText1, strForText2
Close fsave

ErrorHandler:
Exit Sub
End Sub


Thanks

Append Time To Filename
I have a workbook that I've setup so that one of the sheets is exported as a .csv file whenever a button is pushed. Now the enduser want's a file saved for each button push with the time appended to the file name.

Here's what I have:
Dim Today As Variant
Today = Now
Sheets("AHMS Link").Select
Sheets("AHMS Link").Copy
ActiveWorkbook.SaveAs Filename:= _
"C:Documents and SettingsAHMS290My DocumentsWORKAHMSAHMSLINK " & Today & ".csv", FileFormat _
:=xlCSVMSDOS, CreateBackup:=False
ActiveWorkbook.SaveAs Filename:= _
"E:AHMSLINK.csv", FileFormat _
:=xlCSVMSDOS, CreateBackup:=False
ActiveWindow.Close

I get an error 1004 which I believe is due to special characters being thrown in the file name.

What have I botched up?

Cheers!

What's The Best Way To Extract The Filename From This String?
Code:
E:VBDevDemo.pdf


Hi Guys,

What's the best way to extract the filename from this sort of string. Please help.

Server Date/time Instead Of Windows Date/time
Dear VB Experts,

We are developing a Client/Server application whereby the VB executables will reside at the PC.

Server run on HP-UX 10.20. Database is Informix-Online.

One of our task is to utilise the server date and time for timestamp instead of using the Windows date and time.

How do we do that ?

Thanks in advance.

RWS

VB6 - Append Time Stamp To A Filename
Hello everybody.

I have a file: "Emp_Messages.txt". In order to differenciate the times the files were created, I want to append time to each file:
Example: When the first file is created, it will be: "Emp_Messages_1300.txt"
The next file created will be: "Emp_Messages_1310.txt" etc.

I am using [code]Emp_Messages & time() & ".txt" but the syntax is not jiving.

Any help will be appreciated.
Giftx.

Extract Part Of A FileName In A String
Hello all...

I have a string that has a filename in it. The filename is all consistent except for a number that designates our different sites. I am trying to extract that number into a variable, but I cannot figure out how. I have tried the Mid function, but when the number goes from 1, 2, 3 digits I get different results.


Code:
Filename examples:
F2kc1.zip
F2kc20.zip
F2kc300.zip

Mid(strFullPath, 5, 3)

Anyone have any ideas?

Thanks
Garry B

How To Parse A Filename From A Directory String?
Hello,

I have a String "c: estmytest.jpg"

How do I parse the filename from the directory String so that the result would be mytest.jpg?

Opining A File With The Filename As A String
Yo yo yo

When I open a file "Open "Path/to/file" For Input As #2" Everything is fine, but when I use a variable I have an error

Code:
Option Explicit

Public sFile As String

Function CheckFile(File As String) As Boolean
    File = Dir(File)
    
    If File = "" Then
        CheckFile = False
    Else
        CheckFile = True
    End If
End Function

Function CheckData(File As String) As Boolean
    On Error Resume Next
    
    Dim x As String
    
    Open sFile For Input As #2
    'Open sFile "X:ProgrammingVBKarateKontrolKarateKontrols" For Input As #2 -- would work but it is not user defined
        Line Input #2, x
        
        MsgBox x
        
        If x = "KarateKontrol Data File" Then
            CheckData = True
        Else
            CheckData = False
        End If
    Close #2
End Function

Private Sub Form_Load()
    sFile = "X:ProgrammingVBKarateKontrolKarateKontrols"
    
    If CheckFile(sFile) = False And CheckData(sFile) = False Then
        Do
            CommonDialog1.ShowOpen
        Loop Until CheckFile(sFile) = True And CheckData(sFile) = True
    End If
End Sub




Edited by - Cerf on 8/16/2003 1:42:21 PM

How To Print VBA Excel Module Sheets With Filename And Date Printed!
Hi Everyone

Long time since I last posted, but here I am again with an easy one this time!

I have built a rather large VBA Excel based application for our work containing 33 module sheets, 3 forms etc. etc.

It has undergone various modifications in its lifespan. I have made a hardcopy of all the module sheets. However, when the code in any of the module sheets undergoes a modification, I would like to keep the most updated hardcopy version of it. However, I would like to see on the printed module sheet, the name of the file and more importantly the date that this print was made on. I could not find a way of doing it - couldn't even code the header/footer on the module sheet, apparently it hasn't got one!!!!!!!

Any ideas guys, how can I get around to doing this??????????????


Best regards


Deepak Agarwal

GetAttr(filename) Doesn't Work All The Time
Hi folks,

here see this code:


Code:
Dim vul_path As String
List1.Clear
File1.Path = Dir1.Path
Debug.Print "Dir is gevuld"
vul_path = Dir$(Dir1.Path & "", vbDirectory Or vbHidden Or vbReadOnly Or vbSystem)
Do While (vul_path <> "")
Debug.Print "list moet gevuld zijn"
If GetAttr(Dir1.Path & "" & vul_path) = vbDirectory Then
List1.AddItem ("<DIR> " & vul_path)
Else
List1.AddItem (vul_path)
End If
vul_path = Dir$
Loop
DoEvents

for some reason the directory's like "Start menu" doesn't get the <DIR> in front of them why is that? also hidden directory's doesn't get the <DIR> in front of them

Copyright © 2005-08 www.BigResource.com, All rights reserved