PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
saving query-VBForums
Results 1 to 8 of 8

Thread: saving query

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2006
    Posts
    24

    saving query

    Hi guys the below code basicaly saves it as as excel, I also like it to save it as a doc. How would i code so it saves to both csv and doc?

    Open "U:\Results.csv" For Append As #1
    ' the answers are saved in the Csv file. The variables that I have declared at the top are used to save the answers
    ' checks the answer to question 1 and prints it
    Print #1, "1,"; gender
    ' checks the answer to question 2 and prints it
    Print #1, "2,"; age
    ' checks the answer to question 3 and prints it
    Print #1, "3,"; txtheight
    ' checks the answer to question 3 and prints it
    Print #1, "4,"; txtweight
    ' checks the answer to question 4 and prints it
    Print #1, "5,"; activity

    Close #1

  2. #2
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011

    Re: saving query

    Quote Originally Posted by steve khan
    Hi guys the below code basicaly saves it as as excel, I also like it to save it as a doc. How would i code so it saves to both csv and doc?

    Open "U:\Results.csv" For Append As #1
    ' the answers are saved in the Csv file. The variables that I have declared at the top are used to save the answers
    ' checks the answer to question 1 and prints it
    Print #1, "1,"; gender
    ' checks the answer to question 2 and prints it
    Print #1, "2,"; age
    ' checks the answer to question 3 and prints it
    Print #1, "3,"; txtheight
    ' checks the answer to question 3 and prints it
    Print #1, "4,"; txtweight
    ' checks the answer to question 4 and prints it
    Print #1, "5,"; activity

    Close #1
    you want to save it in doc comma separated? then

    Open "U:\Results.doc" For Append As #1
    ' the answers are saved in the Csv file. The variables that I have declared at the top are used to save the answers
    ' checks the answer to question 1 and prints it
    Print #1, "1,"; gender
    ' checks the answer to question 2 and prints it
    Print #1, "2,"; age
    ' checks the answer to question 3 and prints it
    Print #1, "3,"; txtheight
    ' checks the answer to question 3 and prints it
    Print #1, "4,"; txtweight
    ' checks the answer to question 4 and prints it
    Print #1, "5,"; activity

    Give any extension as long as the file format is text... it can be opened with any text editor/word processor...

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2006
    Posts
    24

    Re: saving query

    when I think adding coma Im doing this below. but this is not right. could you show me an example of coming the two?

    Open "U:\Results.doc,csv" For Append As #1

  4. #4
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011

    Re: saving query

    You need to repeat it.. for csv and for doc..
    'for xls
    Open "U:\Results.csv" For Append As #1
    ' the answers are saved in the Csv file. The variables that I have declared at the top are used to save the answers
    ' checks the answer to question 1 and prints it
    Print #1, "1,"; gender
    ' checks the answer to question 2 and prints it
    Print #1, "2,"; age
    ' checks the answer to question 3 and prints it
    Print #1, "3,"; txtheight
    ' checks the answer to question 3 and prints it
    Print #1, "4,"; txtweight
    ' checks the answer to question 4 and prints it
    Print #1, "5,"; activity

    Close #1

    'for doc
    Open "U:\Results.doc" For Append As #1
    ' the answers are saved in the Csv file. The variables that I have declared at the top are used to save the answers
    ' checks the answer to question 1 and prints it
    Print #1, "1,"; gender
    ' checks the answer to question 2 and prints it
    Print #1, "2,"; age
    ' checks the answer to question 3 and prints it
    Print #1, "3,"; txtheight
    ' checks the answer to question 3 and prints it
    Print #1, "4,"; txtweight
    ' checks the answer to question 4 and prints it
    Print #1, "5,"; activity

    Close #1

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,415

    Re: saving query

    If you want to save in actual Word or Excel files you will need to do more work - the code above simply saves text based files (which is not what Word and Excel use, but they can load the data from them).

    If the computer that your program is running on has the relevant programs installed, you can use automation to create the documents. To do this with Excel see the link in my signature, and for Word I think there are examples in the Office Development FAQ.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Oct 2006
    Posts
    24

    Re: saving query

    Thanksa for that moikhan

    If I want to save to two directories say C: and A what would I change?

    VB Code:
    1. 'for doc
    2. Open "U:\Results.doc" For Append As #1

  7. #7
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011

    Re: saving query

    you want to have both files on both drives? or 1 file in C: and 1 file in A:?

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Oct 2006
    Posts
    24

    Re: saving query

    Hi moinkhan
    what i like is if c drive is not aviable then save in A:

    Open "U:\Results.csv" For Append As #1 //using this

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width