Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2012

    Unanswered: how to write current record to server file

    Private Sub Form_AfterUpdate()
    Const DATA_FILENAME As String = "SomeFile.txt"
    Const SERVER_CONN As String = "DRIVER={MySQL ODBC 5.1 Driver};SERVER=;UID=XXXX;PWD=XXXX;Option=3;"
    Dim rs As New ADODB.Recordset
    Dim conn As New ADODB.Connection
    Dim a(0 To 3) As String
    Dim FF As Long
    Dim i As Integer
    Dim strRecord As String
        On Error GoTo errHandler
        FF = FreeFile
        'Open table in this database
        rs.Open "someTable", CurrentProject.Connection, adOpenStatic, adLockReadOnly
        rs.AbsolutePosition = Me.CurrentRecord
        'Assign recordset values to a()
        For i = 0 To rs.Fields.Count - 1
            If IsNull(rs(i)) Then
            a(i) = ""
            a(i) = rs(i)
            End If
        Next i
        'Open output and write record  ** NEEDS TO WRITE TO SERVER FILE
         strRecord = Join(a(), ",")
        Open CurrentProject.Path & "\" & DATA_FILENAME For Append As #FF
        Print #FF, strRecord
    cleanup: blahblah, etc.
    The question is, how do I write variable strRecord to a file on a server?
    I want to do: conn.Open SERVER_CONN , but how do I write strRecord through the conn object?
    Also, my connection string is off, can someone assist me with the correct format to attach to a text file?

    Last edited by PennyLayne; 07-03-13 at 12:04.

  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    Im not to sure what the approved way of connecting to a file in Access is these days
    it used to be open a file for append, then write to the file, then close it using file handles. see Write to external text file - Microsoft: Access Reports FAQ - Tek-Tips or How to write a txt file based on table info? - Access World Forums
    or even

    how that will play in a multi user environment I don't know.

    what you could do is connect to a table in another access db and write to that that table. then when you need the file suck the relevant data from that table
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Dec 2012
    Thanks for your response Healdem.
    I am using the Open for Append method, but it's currently pointing to my local folder. These lines:

    Open CurrentProject.Path & "\" & DATA_FILENAME For Append As #FF
    Print #FF, strRecord

    But this doesn't pass the User Id & Password I need to access the server - which is my dilemma. Seems that I need the connection object or another recordset, but not sure how.

    I checked the links provided. I played around with FSO, but still it doesn't address how to incorporate the UID & PWD that I need to upload anything to the server.
    Last edited by PennyLayne; 07-03-13 at 15:58.

Posting Permissions

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