2014-11-24 2 views
0

Microsoft Access 2002 데이터베이스를 작업 중입니다. 나는 중요한 문제없이 'DoCmd.TransferText'를 사용하여 데이터베이스로 가져 오는 (다른 조직의) 텍스트 파일을 가지고있다. 나는 매달 새로운 파일을 얻고 때로는 파일을 제공하는 외부 조직이 내용, 순서 및/또는 열 수를 변경합니다 (자체 진행중인 개발의 일부로 무작위로 - 나는 예상/희망합니다).'Line Input # 1'을 사용할 때의 글자 수 한도

현재 파일을 데이터베이스로 가져 오기 전에 파일의 레이아웃을 확인하고 변경된 경우 경고 메시지를 표시하는 VBA 프로세스에 코드를 추가하려고합니다. 나는 'Line Input # 1'을 사용하여 열 헤딩을 문자열로 가져 와서 예상 된 열 머리글과 비교할 수 있다고 생각했습니다.

내가 겪고있는 문제는 내가 비교할 필요가 있다고 느끼는 문자의 수가 2,568이지만 '줄 입력 # 1'을 사용할 때 처음 1023자를 얻는 것처럼 보이기 때문에 항상 비교가 실패합니다. 어쨌든 제한을 무시하거나 다음 1023자를 가져 와서 문자열로 결합 할 수 있습니까?

P. 문제의 파일은 캐리지 리턴을 포함하지 않으며 라인 피드 문자 만 포함하므로 'Line Input # 1'메서드가 전체 파일에로드하려고 시도하지만 괜찮습니다. 이론적으로는 실제로는 1023을 수행하는 것입니다. 문자) 그래서 나는 변수의 선언시 문자열 길이를 2,568로 설정하여 나머지 파일을 무시합니다.

Sub FileImport() 

Dim db As Database 
Dim rstFiles As Recordset 
Dim strFileHeaders As String * 2568 'Set Fixed length as we only want to check the first 2,568 characters of the file to confirm layout 
Dim strExpectedHeaders As String * 2568 

strExpectedHeaders = ";;Totals;;;Fixed Charge - Metered Water;;;;;;Volumetric Water Charge - Metered;;;Fixed Charge - Metered Waste Water;;;;;;" & _ 
    "Volumetric Waste Water Charge - Metered;;;Property Drainage Charge (p/£RV);;;;;;Roads Drainage Charge (p/£RV);;;;;;" & _ 
    "Non Domestic Metered Wastewater Fixed Charge;;;;;;Non Domestic Metered Wastewater Volume Charge;;;;;;Fixed Charge - Un-metered Water;;;;;;" & _ 
    "Water RV Charge - Un-metered;;;;;;Fixed Charge - Un-metered Waste Water;;;;;;Volumetric Waste Water Charge - Un-metered;;;;;;" & _ 
    "Supply Contract Discount (Water);;;;;;Supply Contract Discount (Waste);;;;;;Direct Debit Discount;;;;;;Water Management Charge;;;;;;;Meter Read History;;;;" & Chr(10) & _ 
    "Customer reference;Date posted;Bill no;Meter serial no.;From date;To date;Meter size (actual);Meter size (billed);" & _ 
    "Property address;Billing address;Rateable value;Your ref;PURN;Water SPID;Waste water SPID;% Return to sewer;Net total;" & _ 
    "VAT amount;Total amount;Net amount;VAT amount;Total amount;Days charged;Unit cost;Consumption;Net amount;VAT amount;" & _ 
    "Total amount;Days charged;Unit cost 1;Consumption 1;Unit cost 2;Consumption 2;Unit cost 3;Consumption 3;Unit cost 4;" & _ 
    "Consumption 4;Net amount;VAT amount;Total amount;Days charged;Unit cost;Consumption;Net amount;VAT amount;" & _ 
    "Total amount;Days charged;Unit cost 1;Consumption 1;Unit cost 2;Consumption 2;Unit cost 3;Consumption 3;Unit cost 4;" & _ 
    "Consumption 4;Net amount;VAT amount;Total amount;Days charged;Unit cost;Consumption;Net amount;VAT amount;Total amount;" & _ 
    "Days charged;Unit cost;Consumption;Net amount;VAT amount;Total amount;Days charged;Unit cost;Consumption;Net amount;" & _ 
    "VAT amount;Total amount;Days charged;Unit cost;Consumption;Net amount;VAT amount;Total amount;Days charged;Unit cost;" & _ 
    "Consumption;Net amount;VAT amount;Total amount;Days charged;Unit cost;Consumption;Net amount;VAT amount;Total amount;" & _ 
    "Days charged;Unit cost;Consumption;Net amount;VAT amount;Total amount;Days charged;Unit cost;Consumption;Net amount;" & _ 
    "VAT amount;Total amount;Days charged;Discount;Consumption;Net amount;VAT amount;Total amount;Days charged;Discount;" & _ 
    "Consumption;Net amount;VAT amount;Total amount;Days charged;Discount;Consumption;Net amount;VAT amount;Total amount;" & _ 
    "Days charged;Unit cost;Consumption;Measured site area;Meter serial number;Meter location;Current reading date;" & _ 
    "Current meter read method;Current 'Actual/Estimate';Current reading;Previous reading date;Previous 'Actual/Estimate';" & _ 
    "Previous reading;Previous reading date;Previous meter read method;Previous 'Actual/Estimate';Previous reading;Previous reading date;Previous 'Actual/Estimate';Previous reading;" 


Set db = CurrentDb() 

Set rstFiles = CurrentDb.OpenRecordset("SELECT [id], [filename], [path]" & _ 
"FROM [import file] " & _ 
"WHERE (((imported)=False)) ", dbOpenDynaset) 

Do 
    Open rstFiles![Path] & rstFiles![filename] For Input As #1 
    If Not EOF(1) Then Line Input #1, strFileHeaders 
    Close #1 

    If strFileHeaders = strExpectedHeaders Then 
     DoCmd.TransferText acImportDelim, "BS_WWW_Spec", "import - BS WWW", rstFiles![Path] & rstFiles![filename], False, "" 
    Else 
     db.Execute "INSERT INTO [audit] (eventsource, eventmessage) " & _ 
      "VALUES (""Sub FileImport"" ,""Layout of FileID " & rstFiles![ID] & " not recognized"")", dbFailOnError 
    End If 

    rstFiles.MoveNext 

Loop Until rstFiles.EOF 

rstFiles.Close 

End Sub 

답변

0

당신은 line input 대신 input를 사용하려고 할 수 있습니다 : 액세스 2002이있는 경우 그것은 액세스 2010에서 작동

Dim strFileHeaders As String * 2568 

Open rstFiles![Path] & rstFiles![filename] For Input As #1 
Input #1, strFileHeaders 
Close #1 

이, 나도 몰라 여기

지금까지 내 코드입니다 input에 더 제한적인 최대 길이.

관련 문제