Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 2nd, 2006, 08:43 AM
Authorized User
 
Join Date: May 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, i got it working . Thanks. Just need a little bit of help with csv again :)

Just this line im using. Is there a simpler way to do it. so that it works

PropAttachment = GetSystemString("Doc Path") & PropType & "-" & PropID & ".csv"

 
Old June 5th, 2006, 03:42 AM
Authorized User
 
Join Date: May 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

:( Ok im still working away on this. I aint got it working yet. Anyone have any tips?

 
Old June 5th, 2006, 06:24 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

What are you trying to do with this line?

PropAttachment = GetSystemString("Doc Path") & PropType & "-" & PropID & ".csv"

This looks like you are trying to generate a file name. What is "GetSystemString"? Is that a variable or a method?

And why "PropAttachment"? Anyway, if you are trying to build the path and file name, I would suggest not having a space in "Doc Path". If you are snatching these variables from the form, do that before this line, not in the line. So you would do this:

Dim PropAttachment As String
Dim sDocPath As String
Dim sPropType As String
Dim sPropID As String

sDocPath = Me.txtDocPath
sPropType = Me.txtPropType
sPropID = Me.PropID

PropAttachment = sDocPath & "\" & sPropType & "-" & iPropID & ".csv"

I added the "\" cause that usually goes missing.

Don't grab variable values in the line as you have done, get them before, and then concatenate them in line. Also note that even though PropID is prabably an integer, use a string since it will end up as a string and not be used as a number in an equation. When you try to concatenate an integer, sometimes it can cause problems and try to do arithmetic when you just want a regualr expression.

Does this help?


mmcdonal
 
Old June 5th, 2006, 06:25 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Sorry, that's

PropAttachment = sDocPath & "\" & sPropType & "-" & sPropID & ".csv"

not

PropAttachment = sDocPath & "\" & sPropType & "-" & iPropID & ".csv"


mmcdonal
 
Old June 5th, 2006, 07:39 AM
Authorized User
 
Join Date: May 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Basically im trying to fix someones work, but im in the same boat as them. It basically takes the results of a query, puts them into a csv file and attaches the csv file to an email. Ive changed the csv creation back to the original one.

This is the query i have.

SELECT [Clients].[Company Name], [Clients].[Address], [Clients].[Post Code], [Clients].[Sort Code], [Clients].[Acc number], [Clients].[Acc Name], [Proposals].[Date Supplier paid], [Proposals].[Doc Fee], [Proposals].[Commission (£)], [Proposals].[The Goods], [Proposals].[VAT on Commission] AS Expr1, [Proposals].[Fixed /Variable] AS Expr2, [Proposals].[Opt Fee] AS Expr3, [Proposals].Manufacturer AS Expr4, [Proposals].[Chasis Number] AS Expr5, [Proposals].[Final Installment - Balloon] AS Expr6, [Proposals].[Advance Payment] AS Expr7, [Proposals].[Date to First Payment] AS Expr8, [Proposals].[Date of Balloon] AS Expr9, [Proposals].[Serial Number], [Proposals].[Registration Number], [Proposals].[Year Of Manufacture], [Proposals].[New], [Proposals].[Transaction Price(£)], [Proposals].[Transaction Price VAT], [Proposals].[Cash Deposit (£)], [Proposals].[Balance To Finance (£)], [Proposals].[Rental Profile Period], [Proposals].[Rental Profile Details], [Proposal Rental Profiles].[Amount], [Proposals].[Fortis CSV] AS Expr10, [Proposals].[Accepted Finance House]
FROM Products, (Clients INNER JOIN Proposals ON [Clients].[ID]=[Proposals].[ID]) INNER JOIN [Proposal Rental Profiles] ON [Clients].[ID]=[Proposal Rental Profiles].[ID]
WHERE ((([Proposals].[Query CSV])=True) And (([Proposals].[Accepted Finance House])=" Lease"));


 This is the csv creator
DoCmd.TransferText acExportDelim, , "Fortis", "C:\Fortis.csv"


This is the mail to part
Function MailNow(Address, FinanceHouse)
Dim PropID As Long
Dim PropAttachment As String
Dim Found As Boolean
Dim Mesg As String
Dim Subj As String
Dim rcd As New ADODB.Recordset
Dim objWord As Word.Application
On Error GoTo HandleErr
If ProposalFromWizard = True And RemailToFinanceHouse = False Then
    rcd.Open "TempProposals", CurrentProject.Connection, adOpenKeyset, adLockPessimistic, adCmdTableDirect
    rcd.MoveFirst
    PropID = rcd.Fields![ID]
    rcd.Close
    Set objWord = CreateObject("Word.Application")
    Processcsv objWord, PropID, True 'True means Close the Document when finished
    AddOfferToProposal PropID, FinanceHouse
    Mesg = "Proposal for " & GetClientName(Val(SelectedClient)) & " (" & GetClientContact(Val(SelectedClient)) & ")"
Else
    PropID = Forms![Proposals].[ID]
    PropType = Forms![Proposals].[Proposal Type]
    PropType = UCase(Left(PropType, InStr(1, PropType, " ") - 1))
    Set objWord = CreateObject("Word.Application")
    Processcsv objWord, PropID, True 'True means Close the Document when finished
    AddOfferToProposal PropID, FinanceHouse
    Forms![Proposals].pcfinancehouse.Requery
    Mesg = "Proposal for " & GetClientName(Forms![Proposals].[Client ID]) & " (" & GetClientContact(Forms![Proposals].[Client ID]) & ")"
End If
RemailToFinanceHouse = False
Subj = Mesg
Mesg = Mesg & vbCr & vbCr & vbCr
Mesg = Mesg & GetSystemString("Company Name") & vbCr
Mesg = Mesg & "Tel: " & GetSystemString("Phone") & " Fax: " & GetSystemString("Fax") & vbCr
Mesg = Mesg & "E-mail: " & GetSystemString("EMail")
If NewPropType = "PRIVATE" Then

    DoCmd.TransferText acExportDelim, , "Fortis CSV", "C:\Fotris.csv"

Else
    DoCmd.TransferText acExportDelim, , "Fortis CSV", "C:\Fotris.csv"
End If
MakeEmail Address, Subj, Mesg, PropAttachment
ExitHere:
    Exit Function


 
Old June 5th, 2006, 07:48 AM
Authorized User
 
Join Date: May 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When i run this, the CSV file is created, an export log is created but nothing is written into the CVS file. Im so close i think.

 
Old June 5th, 2006, 07:51 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Is the query saved? You can't export a query unless it is saved with a name to it.


mmcdonal
 
Old June 5th, 2006, 07:53 AM
Authorized User
 
Join Date: May 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yeah, the query is saved in the query section of the database.

Allan

 
Old June 26th, 2006, 11:30 AM
Registered User
 
Join Date: Jun 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

I have a similar question about export to csv file. When I use similar way as you guys discussed to export csv file. The accuracy of numbers are lost. In the table, columns have numbers like 1.2345, but in the csv file, the number change to 1.23 always two decimal places. How can I get exactly copy of data in csv file as in the table?

Thanks very much






Similar Threads
Thread Thread Starter Forum Replies Last Post
DataSet export to .csv file snufse1 ASP.NET 2.0 Basics 3 September 22nd, 2008 07:22 AM
Export to Excel as .csv file from JSP naheedv Reporting Services 3 November 30th, 2006 08:04 AM
index lost when export to csv file chacquard Access VBA 1 October 10th, 2006 01:57 PM
How To Export a specific Excel Sheet as a csv file mrjits Excel VBA 5 August 1st, 2006 03:04 PM
Export data in to csv file from asp.netpage madhusrp ASP.NET 1.0 and 1.1 Professional 1 June 9th, 2006 09:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.