Results 1 to 3 of 3
  1. #1
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162

    VBA which adds to a temp table to export is pulling all the data through

    Hi all,

    Im trying to get my code to pull through some data from another table in order to export as a csv. Some data is coming through but other fields arent. Whats happening is a button (the code is below) copies to a holder table - at this point the fields are getting lost. Theres no error it just copies everything apart from costcode and description.

    Code:
    Private Sub ExportCSV_Click()
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
        Dim sHour As String
        Dim sName As String
        Dim sPath As String
        sName = Environ("Username")
        
        'CHANGE THIS PATH IF YOU WANT A SPECIFIC LOCATION FOR THE CSV FILE
        sPath = "d:\test\Output.csv"
     
        Set db = CurrentDb()
        Set rs = db.OpenRecordset("ExportCSVTable", dbOpenDynaset)
        With rs
            .AddNew
            Select Case Me.Hour.Value
            Case Is <> 0
                sHour = "CC"
            Case Else
                sHour = "CD"
            End Select
            !fldType = Nz(sHour, "")
            !fldProjActRef = Me.Project.Column(2) & Me.SubProjectCode
            !fldCostCode = Me.CostCode
            !fldTaskDate = Me.DatePicker
            !fldDescription = Me.Description
            !fldName = Me.LoggedInUser
            !fldQuantity = Me.Hour
            !fldRate = 0
            .Update
            
            .MoveLast
            
            DoCmd.TransferText acExportDelim, , "ExportToCSVQuery", sPath
            
        End With
        
        rs.Close
        db.Close
        Set rs = Nothing
        Set db = Nothing
    
    End Sub
    Any ideas please? Or if I havent explained clearly please specifiy what else you need to know.



    Thanks

  2. #2
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    I'm confused - why are you using code instead of a query? An append query that takes the information from the form as you are doing above.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I don't see anything offhand that would drop those two fields. Have you set a breakpoint, stepped through the code and checked the value coming from those 2 controls?

    http://www.baldyweb.com/Debugging.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Query for temp linked table
    By compooper in forum Programming
    Replies: 8
    Last Post: 06-30-2011, 06:53 AM
  2. Listview pulling data from a second table
    By Yesideez in forum Access
    Replies: 8
    Last Post: 06-29-2011, 05:08 AM
  3. sql temp table creation for form
    By Ian_ in forum Forms
    Replies: 2
    Last Post: 06-17-2011, 03:27 AM
  4. Replies: 0
    Last Post: 07-27-2009, 07:51 AM
  5. Pulling most recent data from child table
    By davidv43 in forum Access
    Replies: 0
    Last Post: 02-07-2009, 11:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums