문제

사용자가 채워야하는 텍스트 상자 필드가 포함 된 Microsoft Access에 팝업 창이 있습니다 (예 :

)
First Name:
Last Name:
.

이제 클릭하면 클릭하면 C : \ MyTextFile.txt를 볼 수있는 버튼을 만들려고합니다. 해당 필드를 자동 채우십시오.

텍스트 파일 안에는 다음과 같습니다.

##$@#%#$543%#$%#$$#%LAST NAME:BOB#$#@$@#$@#$@#FIRST NAME:DERRICK$#%$#%$#%#$%$#%$#
.

본질적으로 나는 3 가지를 찾고 있습니다 :

  1. 텍스트 파일에 액세스하려면
  2. 데이터를 구문 분석합니다
  3. 텍스트 상자에 그것을 채우십시오.(데이터는 "저장"버튼을 클릭 할 때까지 테이블에 들어갈 필요가 없습니다 ")
  4. 업데이트 : 이것은 내가 지금까지 쓴 것입니다. 왜 작동하지 않는지 확신하지 못합니다.

    Private Sub LoadText_Click()
    
        Dim myFile As String myFile = "C:\myFile.txt"
        Me.NameofTextbox = Mid(myFile, 7, 3)
    
    End Sub
    
    .

도움이 되었습니까?

해결책

여기서 제공 한 파일 및 txtboxLastNametxtboxFirstName

의 양식을 제어합니다.
Dim mFields() As String ' array with fields' names in file
Dim mControls() As String ' corresponding controls' names
Dim mStopChars() As String ' Characters that put after values

Dim tmpstr As String
Dim content As String

Dim i As Long
Dim fStart  As Long
Dim valStart As Long
Dim valEnd As Long
Dim FieldValue As String
Dim j As Long
Dim tmp As Long

' prepare maps

' here : included in field name for common case
mFields = Split("LAST NAME:,FIRST NAME:", ",") 
mControls = Split("txtboxLastName,txtboxFirstName", ",")
mStopChars = Split("#,$,@,%", ",")

' read file into string
Open "c:\mytextfile.txt" For Input As #1

Do While Not EOF(1)
    Input #1, tmpstr
    content = content & tmpstr
Loop

Close #1

' cycle through fields and put their values into controls
For i = LBound(mFields) To UBound(mFields)
    fStart = InStr(1, content, mFields(i))
    If fStart > 0 Then
        valStart = fStart + Len(mFields(i))  'value start at this pos
        'cycle through possible stop chars to locate end of current value
        valEnd = Len(content)
        For j = LBound(mStopChars) To UBound(mStopChars)
            tmp = InStr(valStart, content, mStopChars(j))
            If tmp > 0 Then
                If tmp <= valEnd Then
                    valEnd = tmp - 1
                End If
            End If
        Next j
        ' cut value
        FieldValue = Mid(content, valStart, valEnd - valStart + 1)
        ' assign to control
        Me.Controls(mControls(i)).Value = FieldValue
    End If
Next i
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top