Results 1 to 24 of 24

Thread: Submit button

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Long Island, NY.
    Posts
    353

    Question 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:
    1. Dim tmp As Date
    2. tmp = Format(Day(Date), "dddd")
    3.  
    4. 'to get weekending (if friday)
    5. Dim Dte As Date
    6. Dte = Date
    7. Do Until Format(Day(Dte), "dddd") = Friday
    8. Dte = DateAdd("d", 1, Dte)
    9. Loop
    10.  
    11. 'Dte now = Firdays Date

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    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:
    1. Dim fName As String 'filename
    2. Dim CDFile As String 'filename from common dialog
    3. 'gets current day "monday","Tuesday" etc...
    4. Dim tmp As String
    5.  
    6. tmp = Format(Date, "dddd")
    7. 'to get weekending (if friday)
    8. Dim Dte As Date
    9. Dte = Date
    10. Do Until Format(Dte, "dddd") = "Friday"
    11. Dte = DateAdd("d", 1, Dte)
    12. Loop
    13. 'Dte now = Firdays Date
    14. CommonDialog1.InitDir = "C:\"
    15. CommonDialog1.ShowOpen
    16. If CommonDialog1.FileName = "" Then Exit Sub
    17. CDFile = CommonDialog1.FileName
    18. fName = Right(CDFile, Len(CDFile) - InStrRev(CDFile, "\")) 'gets just the filename
    19. 'if you want todays date in the file name
    20. FileCopy CDFile, "C:\Temp\Dte\tmp\" & Format(Date, "dd_mm_yyyy") & fName
    21. 'if you want fridays date
    22. 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"

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Long Island, NY.
    Posts
    353

    Re: Submit button

    What is this:
    VB Code:
    1. CommonDialog1.InitDir = "C:\"
    2. CommonDialog1.ShowOpen
    3. If CommonDialog1.FileName = "" Then Exit Sub
    4. CDFile = CommonDialog1.FileName
    5. fName = Right(CDFile, Len(CDFile) - InStrRev(CDFile, "\"))

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Submit button

    Quote Originally Posted by vonoventwin
    What is this:
    VB Code:
    1. CommonDialog1.InitDir = "C:\"
    2. CommonDialog1.ShowOpen
    3. If CommonDialog1.FileName = "" Then Exit Sub
    4. CDFile = CommonDialog1.FileName
    5. 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.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Long Island, NY.
    Posts
    353

    Re: Submit button

    So when this code executes it will come up with the file browser??

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Submit button

    Quote Originally Posted by vonoventwin
    So when this code executes it will come up with the file browser??
    Yes...

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Long Island, NY.
    Posts
    353

    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!

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Submit button

    Quote 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.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Long Island, NY.
    Posts
    353

    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:
    1. 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)..

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Long Island, NY.
    Posts
    353

    Re: Submit button

    Quote 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?

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Long Island, NY.
    Posts
    353

    Re: Submit button

    Quote 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.

  13. #13
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Submit button

    Quote 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.

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Long Island, NY.
    Posts
    353

    Re: Submit button

    Great I'm already nervous!

  15. #15
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    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:
    1. If Len(Dir("C:\" & Format(Dte,"dd_mm_yyyy"),vbDirectory)) = 0 then
    2. mkDir ("C:\" & Format(Dte,"dd_mm_yyyy")
    3. end if
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Long Island, NY.
    Posts
    353

    Re: Submit button

    Thanks. They directory will definitely not exist so I will always have to have it created.

  17. #17
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Submit button

    Quote 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?

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Long Island, NY.
    Posts
    353

    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:
    1. Dim fName As String 'filename
    2.  
    3. Dim CDFile As String 'filename from common dialog
    4.  
    5. 'gets current day "monday","Tuesday" etc...
    6. Dim tmp As String
    7. tmp = Format(Date, "dddd")
    8.  
    9.  
    10. 'to get weekending (if friday)
    11. Dim Dte As Date
    12. Dte = Date
    13. Do Until Format(Dte, "dddd") = "Friday"
    14. Dte = DateAdd("d", 1, Dte)
    15. Loop
    16.  
    17. If Len(Dir("C:\" & Format(Dte, "dd_mm_yyyy"), vbDirectory)) = 0 Then
    18. MkDir ("C:\" & Format(Dte, "dd_mm_yyyy"))
    19. End If
    20.  
    21. 'Dte now = Firdays Date
    22.  
    23. CDFile = "C:\Temp\brad\temp.doc"
    24. fName = Right(CDFile, Len(CDFile) - InStrRev(CDFile, "\")) 'gets just the filename
    25.  
    26. 'if you want todays date in the file name
    27. FileCopy CDFile, "C:\Temp\Dte\tmp\" & Format(Date, "dd_mm_yyyy") & fName
    28.  
    29. 'if you want fridays date
    30. FileCopy CDFile, "C:\Temp\Dte\tmp\" & Format(Dte, "dd_mm_yyyy") & fName

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Long Island, NY.
    Posts
    353

    Re: Submit button

    Quote 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.

  20. #20
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Submit button

    Quote 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?

  21. #21

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Long Island, NY.
    Posts
    353

    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...

  22. #22

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Long Island, NY.
    Posts
    353

    Re: Submit button

    VB Code:
    1. FileCopy CDFile, "C:\Temp\Dte\tmp\" & Format(Date, "dd_mm_yyyy") & fName
    Path not found

  23. #23
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Submit button

    That means the folder didn't get created. If you did
    VB Code:
    1. Msgbox CDFile, "C:\Temp\Dte\tmp\" & Format(Date, "dd_mm_yyyy") & fName
    What do you see?

  24. #24
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Submit button

    I've been doing some testing, and this works. Modify as needed.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" _
    4. (ByVal lpPath As String) As Long
    5.  
    6. Private Sub Command1_Click()
    7. Dim FName As String
    8. Dim FName1 As String
    9. FName = "test.txt"
    10. FName1 = Format(Date, "dd_mm_yyyy") & FName & "\"
    11. MakeSureDirectoryPathExists "c:\rmg\" & FName1
    12. 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
  •  



Click Here to Expand Forum to Full Width