|
* 답변하시는 분들께 도움이 되도록 자신의 환경을 아래 항목 옆에 기재해 주세요.
- 액세스 버전(95,97,2000,xp,2003,2007): 액세스 2016
* 아래줄에 질문을 작성하세요 >>
액세스 책 사서 혼자 공부하면서 업로드 폼을 하나 만들고 있는데요...
텍스트파일을 불러와서 특정 테이블에 데이터를 나눠서 저장하고 싶어요.
... 중요한 건 불러올려는 데이터가 정해진 틀은 있는데
내용이 바뀐다는거죠..
아래의 텍스트 파일을 불러왔을 때 'AAA'부분은 특정 테이블 'AAA' 필드로
'BB' 부분은 'BB' 필드에 집어넣고 싶은데요..
구분:(AAA)
작성자:(BBB)수정자(CCC)입니다.
(DDDDD)
(EE/FF/GGG)
내용:
(FFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFF)
제가 말씀을 너무 어렵게 드리는 것 같은데.. ㅠㅠ
- 폼에서 '불러오기'를 누른다.
- 텍스트 파일을 선택하고 불러오면 텍스트파일 내 추출해야할
부분들을 추출해서 테이블에 저장한다.
- 텍스트 파일은 기본 포맷(추출할 글자의 위치)은 정해져 있으나
'FF' 부분은 추출할 내용이 가변(추출 라인이 적을수도, 많을수도)이다..
인데.. 인터넷 구글링을 해봐도 위 내용에 대한 명쾌한 해답을
못찼았습니다.. 능력자분의 도움이 절실히 필요합니다.. ㅠㅠ
==============[김종호님 글에 대한 답변입니다]==============
If IsNull(txt_file) Then
Exit Sub
End If
Dim strFileName
Dim strText
Dim i
i = 0
strText = ""
Close #1
strFileName = Me.txt_file 'CurrentProject.Path & "\181203.txt"
If Dir(txt_file) <> "" Then
Open strFileName For Input As #1
While Not EOF(1)
Line Input #1, strText
i = i + 1
If i = 1 Then
If InStr(strText, "구분:(") > 0 Then
Me.AA = Mid(strText, InStr(strText, "(") + 1, InStr(strText, ")") - InStr(strText, "(") - 1)
Else
MsgBox "파일 구조 오류"
Exit Sub
End If
End If
If i = 2 Then
If InStr(strText, "작성자:(") > 0 Then
Me.BB = Mid(strText, InStr(strText, "(") + 1, InStr(strText, ")") - InStr(strText, "(") - 1)
Me.CC = Mid(strText, InStrRev(strText, "(") + 1, InStrRev(strText, ")") - InStrRev(strText, "(") - 1)
End If
End If
If i = 3 Then
If InStr(strText, "(") > 0 Then
Me.DD = Mid(strText, InStr(strText, "(") + 1, InStr(strText, ")") - InStr(strText, "(") - 1)
End If
End If
If i = 4 Then
If InStr(strText, "(") > 0 Then
Me.EE = Mid(strText, InStr(strText, "(") + 1, InStr(strText, "/") - InStr(strText, "(") - 1)
Me.FF = Mid(strText, InStr(strText, "/") + 1, InStr(InStr(strText, "/") + 1, strText, "/") - InStr(strText, "/") - 1)
Me.GG = Mid(strText, InStrRev(strText, "/") + 1, InStrRev(strText, ")") - InStrRev(strText, "/") - 1)
End If
End If
If i >= 6 Then
If InStr(strText, "(") > 0 Then
Me.HH = Mid(strText, InStr(strText, "(") + 1, Len(strText))
Else
Me.HH = Me.HH + strText
End If
End If
Wend
Close #1
If InStr(Me.HH, ")") > 0 Then
Me.HH = Replace(Me.HH, ")", "")
End If
End If
Exit Sub
errs:
MsgBox "오류"
조건 : 파일내 라인 구조가 동일
첨부파일 참조하세요
|
|