|
-
Oct 19th, 2005, 09:23 AM
#1
Thread Starter
Hyperactive Member
Submit button
When a user hits submit I want it to send a file to:
C:\Temp\Dte\tmp
Where Dte is updated from code and tmp is updated from the code. It can be anyfile. So say they use a browse command to find a file on their HD, then they hit submit and it sends it to this location where Dte and tmp change according to this code provided from [A51g]Static.
Here is the original thread with more details...
VB Code:
Dim tmp As Date
tmp = Format(Day(Date), "dddd")
'to get weekending (if friday)
Dim Dte As Date
Dte = Date
Do Until Format(Day(Dte), "dddd") = Friday
Dte = DateAdd("d", 1, Dte)
Loop
'Dte now = Firdays Date
-
Oct 19th, 2005, 09:48 AM
#2
Re: Submit button
a) I screwed up that code above.. should have tested it first lol..
you cant use Day() in the format..
b) add a common dialog control to your form
VB Code:
Dim fName As String 'filename
Dim CDFile As String 'filename from common dialog
'gets current day "monday","Tuesday" etc...
Dim tmp As String
tmp = Format(Date, "dddd")
'to get weekending (if friday)
Dim Dte As Date
Dte = Date
Do Until Format(Dte, "dddd") = "Friday"
Dte = DateAdd("d", 1, Dte)
Loop
'Dte now = Firdays Date
CommonDialog1.InitDir = "C:\"
CommonDialog1.ShowOpen
If CommonDialog1.FileName = "" Then Exit Sub
CDFile = CommonDialog1.FileName
fName = Right(CDFile, Len(CDFile) - InStrRev(CDFile, "\")) 'gets just the filename
'if you want todays date in the file name
FileCopy CDFile, "C:\Temp\Dte\tmp\" & Format(Date, "dd_mm_yyyy") & fName
'if you want fridays date
FileCopy CDFile, "C:\Temp\Dte\tmp\" & Format(Dte, "dd_mm_yyyy") & fName
filecopy Source,Destination
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Oct 19th, 2005, 11:24 AM
#3
Thread Starter
Hyperactive Member
Re: Submit button
What is this:
VB Code:
CommonDialog1.InitDir = "C:\"
CommonDialog1.ShowOpen
If CommonDialog1.FileName = "" Then Exit Sub
CDFile = CommonDialog1.FileName
fName = Right(CDFile, Len(CDFile) - InStrRev(CDFile, "\"))
-
Oct 19th, 2005, 11:26 AM
#4
Re: Submit button
 Originally Posted by vonoventwin
What is this:
VB Code:
CommonDialog1.InitDir = "C:\"
CommonDialog1.ShowOpen
If CommonDialog1.FileName = "" Then Exit Sub
CDFile = CommonDialog1.FileName
fName = Right(CDFile, Len(CDFile) - InStrRev(CDFile, "\"))
It is an example of how to use the Common Dialog control to select and open a file.
-
Oct 19th, 2005, 11:30 AM
#5
Thread Starter
Hyperactive Member
Re: Submit button
So when this code executes it will come up with the file browser??
-
Oct 19th, 2005, 11:44 AM
#6
Re: Submit button
 Originally Posted by vonoventwin
So when this code executes it will come up with the file browser??
Yes...
-
Oct 19th, 2005, 12:31 PM
#7
Thread Starter
Hyperactive Member
Re: Submit button
Ok just making sure... I have VB at home so can't try it here at work b/c I can only use VBA here. Thanks!
-
Oct 19th, 2005, 12:38 PM
#8
Re: Submit button
 Originally Posted by vonoventwin
Ok just making sure... I have VB at home so can't try it here at work b/c I can only use VBA here. Thanks!
Just make sure you have a common dialog control on your form.
It may sound silly to say that, but a number of people have posted questions about using the dialog control without actually having one available for use.
-
Oct 19th, 2005, 12:38 PM
#9
Thread Starter
Hyperactive Member
Re: Submit button
How would I alter the code to send a specific file without looking one up (I normally have syntax issues):
VB Code:
CDFile = "C:\Documents and Settings\brad.vonoven\Desktop\DP.doc"
Would that just send the specific file to "C:\Temp\19_10_2005\21_10_2005"?? Assuming it's sent today (19Oct2005) and Friday is the (21Oct2005)..
-
Oct 19th, 2005, 12:44 PM
#10
Re: Submit button
If you know the name of the file and its path, then you probably don't need to use the CommonDialog control.
But, in your first post in this thread you indicate that it could be any file, so that is why we have taken the commondialog approach.
-
Oct 19th, 2005, 12:57 PM
#11
Thread Starter
Hyperactive Member
Re: Submit button
 Originally Posted by Hack
Just make sure you have a common dialog control on your form.
It may sound silly to say that, but a number of people have posted questions about using the dialog control without actually having one available for use.
I don't have anything yet. I am just forshadowing so when I get home I can try it. Now VBA doens't allow this does it? Everytime I try to add a Microsoft Common Dialog Control, Version 6 it says "You don't have the license required to use this Active X control". I just wanted to test it, but will it work it VB6?
-
Oct 19th, 2005, 01:00 PM
#12
Thread Starter
Hyperactive Member
Re: Submit button
 Originally Posted by Hack
If you know the name of the file and its path, then you probably don't need to use the CommonDialog control.
But, in your first post in this thread you indicate that it could be any file, so that is why we have taken the commondialog approach.
Some stations code will have the same file that is updated by a batch file everyday. Others the user will select the files. That's why I was asking both. Thanks for helping me though. I'm a VB noob and I'm gonna have a hard time when I take Computer Programming 2 in the Spring, which I already failed last Spring. It's crazy though I made an "A" in 1, but failed 2. In 1 we just wrote the programs however we wanted to, but in 2 we just had tests on what code for this and that.
-
Oct 19th, 2005, 01:46 PM
#13
Re: Submit button
 Originally Posted by vonoventwin
It's crazy though I made an "A" in 1, but failed 2. In 1 we just wrote the programs however we wanted to, but in 2 we just had tests on what code for this and that.
2 is what you are going to face out in the job world.
-
Oct 19th, 2005, 02:21 PM
#14
Thread Starter
Hyperactive Member
Re: Submit button
Great I'm already nervous!
-
Oct 19th, 2005, 02:40 PM
#15
Re: Submit button
bah.. I never took any classes self taught (and I actually have a job programming! )
another thing you will need to do in your code.
check to see if the directory exists.. if not then u need to create it
something like this:
VB Code:
If Len(Dir("C:\" & Format(Dte,"dd_mm_yyyy"),vbDirectory)) = 0 then
mkDir ("C:\" & Format(Dte,"dd_mm_yyyy")
end if
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Oct 20th, 2005, 06:52 AM
#16
Thread Starter
Hyperactive Member
Re: Submit button
Thanks. They directory will definitely not exist so I will always have to have it created.
-
Oct 20th, 2005, 06:53 AM
#17
Re: Submit button
 Originally Posted by vonoventwin
Thanks. They directory will definitely not exist so I will always have to have it created.
But, you will only have to create it once per machine right?
-
Oct 20th, 2005, 06:58 AM
#18
Thread Starter
Hyperactive Member
Re: Submit button
So far this is what I got and I'm trying my best to see how it will work in VBA (since I dont have VB at work). Will anyone put it in VB for me and send it to me working. I want to see how it works. Make sure you create a Word .doc in file/folder C:\Temp\brad\ and name it temp.doc
VB Code:
Dim fName As String 'filename
Dim CDFile As String 'filename from common dialog
'gets current day "monday","Tuesday" etc...
Dim tmp As String
tmp = Format(Date, "dddd")
'to get weekending (if friday)
Dim Dte As Date
Dte = Date
Do Until Format(Dte, "dddd") = "Friday"
Dte = DateAdd("d", 1, Dte)
Loop
If Len(Dir("C:\" & Format(Dte, "dd_mm_yyyy"), vbDirectory)) = 0 Then
MkDir ("C:\" & Format(Dte, "dd_mm_yyyy"))
End If
'Dte now = Firdays Date
CDFile = "C:\Temp\brad\temp.doc"
fName = Right(CDFile, Len(CDFile) - InStrRev(CDFile, "\")) 'gets just the filename
'if you want todays date in the file name
FileCopy CDFile, "C:\Temp\Dte\tmp\" & Format(Date, "dd_mm_yyyy") & fName
'if you want fridays date
FileCopy CDFile, "C:\Temp\Dte\tmp\" & Format(Dte, "dd_mm_yyyy") & fName
-
Oct 20th, 2005, 07:00 AM
#19
Thread Starter
Hyperactive Member
Re: Submit button
 Originally Posted by Hack
But, you will only have to create it once per machine right?
But according to what the date (tmp) and what week ending date (Dte) is, the directory will be new, correct. For this week directory will stay the same with different subdirectories within it. But next week it will have a new directory.
-
Oct 20th, 2005, 07:14 AM
#20
Re: Submit button
 Originally Posted by vonoventwin
But according to what the date (tmp) and what week ending date (Dte) is, the directory will be new, correct. For this week directory will stay the same with different subdirectories within it. But next week it will have a new directory.
Right...my mistake. We started all of this yesterday and I forgot your original request. I just re-read it. Sorry about that.
So, it looks like your code should work. Are you having issues with any part of it and if so, what and where?
-
Oct 20th, 2005, 07:56 AM
#21
Thread Starter
Hyperactive Member
Re: Submit button
Well will this code run in VBA, if so I can test it now. If not I will have to test it tonight at home...
-
Oct 20th, 2005, 08:01 AM
#22
Thread Starter
Hyperactive Member
Re: Submit button
VB Code:
FileCopy CDFile, "C:\Temp\Dte\tmp\" & Format(Date, "dd_mm_yyyy") & fName
Path not found
-
Oct 20th, 2005, 12:13 PM
#23
Re: Submit button
That means the folder didn't get created. If you did
VB Code:
Msgbox CDFile, "C:\Temp\Dte\tmp\" & Format(Date, "dd_mm_yyyy") & fName
What do you see?
-
Oct 20th, 2005, 12:34 PM
#24
Re: Submit button
I've been doing some testing, and this works. Modify as needed.
VB Code:
Option Explicit
Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" _
(ByVal lpPath As String) As Long
Private Sub Command1_Click()
Dim FName As String
Dim FName1 As String
FName = "test.txt"
FName1 = Format(Date, "dd_mm_yyyy") & FName & "\"
MakeSureDirectoryPathExists "c:\rmg\" & FName1
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|