Results 1 to 5 of 5

Thread: Programming Modules in Access

  1. #1

    Thread Starter
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    OK, I need some guidance here.

    I wrote a VB frontend to an Access database part of which writes data to files from the database.

    I am now trying to put that code into the database itself. Can someone pleas etell me how to change this so it works.

    Code:
    Public Function WriteDIS() As Long
    Dim strSQL As String
    Dim rstTemp As Recordset
    Dim FNum As Integer
    
    On Error GoTo ErrHandler
    
    
    FNum = FreeFile
    
    'DIS_FILE is a const declared elsewhere
    'eg c:\dis.txt
    Open DIS_FILE For Output As FNum
    
    '''S10 type
    strSQL = "SELECT * FROM tblSupplier;"
    Set rstTemp = db.OpenRecordset(strSQL)
    
    While Not rstTemp.EOF
      Print #FNum, "S10|" & rstTemp!SupplierCode & "|" & rstTemp!CompanyName
      rstTemp.MoveNext
    Wend
    rstTemp.Close
    
    '''''S3 type
    'strSQL = "SELECT tblSupplierTP.SupplierCode, tblSupplierTP.TPCode, tblSupplier.ContactName" & _
    '" FROM tblSupplierTP INNER JOIN tblSupplier ON tblSupplierTP.SupplierCode = tblSupplier.SupplierCode;"
    
    'this has been altered to cater for contact names at buisness level
    strSQL = "SELECT * FROM tblSupplierTP;"
    
    Set rstTemp = db.OpenRecordset(strSQL)
    
    While Not rstTemp.EOF
      Print #FNum, "S3|" & rstTemp!SupplierCode & "DIS" & rstTemp!TpCode & "|" & rstTemp!ContactName
      rstTemp.MoveNext
    Wend
    rstTemp.Close
    
    
    '''S30 type
    strSQL = "SELECT * FROM tblSupplierTP;"
    Set rstTemp = db.OpenRecordset(strSQL)
    
    While Not rstTemp.EOF
      Print #FNum, "S30|" & rstTemp!SupplierCode & "DIS" & rstTemp!TpCode & "|" & rstTemp!ccode & Trim0(rstTemp!acode) & rstTemp!FaxNo
      rstTemp.MoveNext
    Wend
    rstTemp.Close
    
    WriteDIS = 0
    
    WriteExit:
      Close #FNum
    Exit Function
    ErrHandler:
      WriteDIS = Err.Number
      GoTo WriteExit
    Close #FNum
    
    End Function
    Many thanks!

    ------------------
    Mark Sreeves
    Analyst Programmer

    [email protected]
    A BMW Group Company



  2. #2
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105

    Post

    I don't know that you can. You'll need a component/library that doesn't exist in Access (and I can't find a way to add one like you can in VB).

    I could be wrong...

  3. #3
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    Hi Mark

    This code works fine for me in an Access module:

    Code:
    Private Sub DoSomething()
        
        Dim db As Database
        Dim rs As Recordset
        
        Set db = Access.CurrentDb
        
        Set rs = db.OpenRecordset("Select * from Customers")
        
        Open "C:\test.dat" For Output As #1
        
        Do Until rs.EOF = True
            Write #1, , rs.Fields("CUSTOMERID").Value
            rs.MoveNext
        Loop
        
        Close #1
        
        rs.Close
        Set rs = Nothing
        
        db.Close
        Set db = Nothing
        
    End Sub

  4. #4

    Thread Starter
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    Thanks for that Clunietp

  5. #5
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    No problem Mark

    be sure to check out your other post too, you'll need both pieces of the puzzle...
    http://www.vb-world.net/ubb/Forum3/HTML/002809.html

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