PDA

View Full Version : Solved: docmd.transfertext



Movian
07-05-2012, 08:18 AM
Hey,
I am trying to setup a quick an reliable Export Import System for single records. after some google searching i discovered the docmd.transfertext command.

However it doesn't seem i can use an SQL statement in the 3rd field to provide the table and record i wish to export.

DoCmd.TransferText acExportDelim, , "SELECT * FROM tblPatient WHERE [MedicalID#] = '" & Me.MedicalID & "'", saveloc

I essentially need this to create a backup as somehow one of my clients employees is deleting the information from this table. Need a quick way for them to restore single records.

Any help appreciated, hoping for a response ASAP!

Movian
07-05-2012, 09:55 AM
Ended up coding my own delimited push and pull system. Not really what I wanted to do but time was a factor, here for prosperity.

Case "Import Demo"

strFilter = ahtAddFilterItem(strFilter, "Image File (*.CSV)", "*.CSV")
Location = ahtCommonFileOpenSave(, SharedFolderLoc & "\PatientCharts\" & Me.lastname & ", " & Me.firstname & " (" & Me.MedicalID & ")", strFilter, , , , "Locate Patient Photo", , True)
DoCmd.Close acForm, "frmMain"
Set fso = New FileSystemObject
Set fsofile = fso.OpenTextFile(Location, ForReading, False)
importTxt = fsofile.ReadLine
splitText = Split(importTxt, "|")
myrs.Open "SELECT * FROM tblPatient WHERE [MedicalID#] = '" & splitText(0) & "'", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
counter = 0
For Each fld In myrs.fields
On Error Resume Next
myrs(fld.Name) = splitText(counter)
myrs.Update
On Error GoTo 0
counter = counter + 1
Next
myrs.Close
Set myrs = Nothing
DoCmd.OpenForm "frmMain"
MsgBox "Complete"
Case "Export Demo"
DoCmd.RunCommand acCmdSaveRecord
saveloc = SharedFolderLoc & "\PatientCharts\" & Me.lastname & ", " & Me.firstname & " (" & Me.MedicalID & ")\" & CStr(Format(Me.CurrDate, "YYYY-MM-DD")) & "-Demographics.csv"
myrs.Open "SELECT * FROM tblPatient WHERE [MedicalID#] = '" & Me.MedicalID & "'", CurrentProject.Connection, adOpenKeyset, adLockReadOnly
exporttxt = ""
For Each fld In myrs.fields
exporttxt = exporttxt & fld.Value & "|"
Next
Set fso = New FileSystemObject
Set fsofile = fso.OpenTextFile(saveloc, ForWriting, True)
fsofile.WriteLine exporttxt
fsofile.Close
myrs.Close
Set myrs = Nothing
MsgBox "Complete"