Option Compare Database
Option Explicit
Public Sub Pick1File()
Dim vFile
vFile = UserPick1File()
If vFile <> "" Then
'do somethin with file
ImportTxtData vFile
End If
End Sub
'load data into form
Public Sub ImportTxtData(ByVal pvFile)
Dim vLine, vSerial, vBitKey, vRecover
Dim i As Integer
Close 1
Open pvFile For Input As #1
Line Input #1, vLine
While Not EOF(1)
Select Case True
Case InStr(vLine, "Serial") > 0
i = InStr(vLine, ":")
vSerial = Trim(Mid(vLine, i + 1))
Case InStr(vLine, "Bitlocker Key") > 0
i = InStr(vLine, ":")
vBitKey = Trim(Mid(vLine, i + 1))
Case InStr(vLine, "Bitlocker Recovery Key") > 0
Line Input #1, vLine
Line Input #1, vLine
vRecover = Trim(vLine)
End Select
Line Input #1, vLine
Wend
Close 1
'fill in form boxes..rename them to YOUR CONTROL NAMES
txtMachName = vSerial
txtBitlocker = vBitKey
txtvRecover = vRecover
End Sub
Public Function UserPick1File(Optional pvPath)
Dim strTable As String
Dim strFilePath As String
Dim sDialogMsg As String, sDecr As String, sExt As String
Const msoFileDialogViewList = 1
Const msoFileDialogSaveAs = 2
Const msoFileDialogFilePicker = 3
Dim lFilterIndex As Long
'getFilterTxt pvFilter, sDecr, sExt, sDialog
If IsMissing(pvPath) Then pvPath = "c:\"
''SetFileFilter pvFilter, sDecr, sExt, sDialogMsg
'Application.FileDialog(msoFileDialogSaveAs) =2 'SAVE AS
'Application.FileDialog(msoFileDialogFilePicker) =3 'file OPEN
With Application.FileDialog(3) 'REFERENCE not needed now : Microsoft Office XX.0 Object Library
.AllowMultiSelect = True
.Title = sDialogMsg ' "Locate a file to Import"
.ButtonName = "Import"
.Filters.Clear
'.Filters.Add sDecr, sExt
'.Filters.Add "Access Files", "*.accdb;*.mdb"
'.Filters.Add "Excel Files", "*.xlsx"
'.Filters.Add "_All Files", "*.*"
.Filters.Add "Text Files", "*.txt"
For lFilterIndex = 1 To .Filters.Count
'Debug.Print lFilterIndex, .Filters(lFilterIndex).Description
'get pdf format from type filter
If InStr(.Filters(lFilterIndex).Description, "PDF") > 0 Then
.FilterIndex = lFilterIndex
Exit For
End If
Next
.InitialFileName = pvPath
.InitialView = msoFileDialogViewList 'msoFileDialogViewThumbnail
If .show = 0 Then
'There is a problem
Exit Function
End If
'Save the first file selected
UserPick1File = Trim(.SelectedItems(1))
End With
End Function