2016-01-18 60 views
0

我試圖創建,看起來完全一樣的Access數據庫的文本文件自定義的文本文件:創建從Microsoft Access

CADWorx P&ID Drop Down List Configuration File. 

Notes: 

-This file contains information on what 
appears in the drop down list in the 
CEDIT Additional Data Dialog 

-Entries should be separated by a semi-colon (;) 

-If a value is not set, an edit box will appear 
in the CEDIT Additional Data Dialog instead 
of a drop down list. 

-Example: AREA_=031;032;033;034A;034B; 
Example: SERVICE_=AEC;HW;LH;CCH; 



[DOCUMENTATION] 
TYPE_= 
DATESUB_= 
DATEAPR_= 
CREATEBY_= 
APRBY_= 


[LINE] 
SERVICE_=OIL;FUEL GAS; 
AREA_= 
UNIT_= 
COUNT_= 
TYPE_= 
RATING_= 
FLGFACE_= 
DESIGNPSI_= 
DESIGNDEG_= 
LINE_NUM_= 
OPERPSI_= 
OPERDEG_= 
SPECPRESS_= 
SPECTEMP_= 
MINDEG_= 
TESTPSI_= 
INSULATE_= 
HEATTRACE_= 
XRAY_= 
CODE_= 
JOINTEFF_= 
WELDPROC_= 
INSPECT_= 
MATPIPE_= 
COMPNOTE_= 
NOTE_= 
USER1_= 

所有字段左側(以「_ =」爲此)是我的數據庫中的字段標題。然後如上所述,這些字段的值必須添加並用分號分隔。我一直在研究一個多星期,幾乎只是在Access中使用文本文件自定義來達到死角。有人可以告訴我這是否要走嗎?或者我應該將數據導出到Excel並從那裏創建文本文件?

非常感謝您的幫助。提前致謝。

+0

請編輯您的問題,刪除截圖,而不是複製並粘貼文本並將其格式化爲代碼。實際上,只保留相關部分,參見[mcve] – Andre

+0

而且重要的是:文件的哪些部分是恆定的,哪些部分是從數據庫中填充的? – Andre

回答

0

這裏的基本知識,寫記錄到文件中:

Dim dbs As Database 
Dim rst As Recordset 
Dim intFileDesc As Integer  'File descriptor for output file (number used by OS) 
Dim strOutput As String   'Output string for entry 
Dim strRecordSource As String 'Source for recordset, can be SQL, table, or saved query 
Dim strOutfile As String  'Full path to output file 

Kill strOutfile     'Delete the output file before using it. 
           'Not necessary, but ensures you have a clean copy every time 
intFileDesc = FreeFile   'Get a free file descriptor 
Open strOutfile For Binary As #intFileDesc 'Open the output file for writing 
Set dbs = CurrentDb 
Set rst = dbs.OpenRecordset(strRecordSource) 'open the recordset based on our source string 
With rst 'make things easier for ourselves 
While Not .EOF 
     strOutput = !Field1 & ";" & !Field2 & ";" & !Field3 
     Print #intFileDesc, strOutput 'Print output string to file 
     .MoveNext  'Advance to next record in recordset 
    Wend 
    .Close     'Close this recordset 
End With 
Close #intFileDesc   'Close output file 
Set rst = Nothing 
Set dbs = Nothing  'Garbage handling before we exit the function 

的基本路線是這樣的:

Print #intFileDesc, strOutput 'Print output string to file 

通過

你可以寫在一次一行。

因此,建立一個功能,在此基礎上進行擴展,逐行創建輸出(包括空行),直到完成。而已。

它需要很多的代碼,但確實是非常微不足道的。而且這樣的輸出沒有其他方法。