Article View: pl.comp.bazy-danych.msaccess
Article #137577Re: Zapis ścieżki do pliku w polu tekstowym
From: Zbigniew Bratko
Date: Fri, 23 Mar 2018 17:46
Date: Fri, 23 Mar 2018 17:46
151 lines
5637 bytes
5637 bytes
W dniu 2018-03-23 o 13:08, Phantom pisze:
> Witam
>
> Potrzebuję zapisywać ścieżki do konkretnych plików pdf znajdujących się na dysku komputera.
> Moja wizja jest taka:
> 1. w formularzu mam przycisk "podepnij pdf..";
> 2. po kliknięciu otwiera się eksplorator windows;
> 3. Wybieram lokalizację pliku pdf;
> 4. Klikam w plik: FV1002018.pdf;
> 5. Zapisuje mi się ścieżka np.: w polu formularza "[ScPliku]" o treści: C:\Faktury\2018\PDF\FV1002018.pdf
>
> Proszę o pomoc lub odesłanie do jakiegoś linku historycznego, który mi pomoże.
Przykładowy kod ze strony:
http://www.faq.accdb.pl/24a_ApiDlgFaq.htm#api24a_02
'5.2 Jak wyświetlić okno dialogowe " Otwórz plik " lub " Zapisz plik "
'- wersja uproszczona (wybór tylko jednego pliku) ?
Private Declare Function GetSaveFileName Lib "comdlg32.dll" _
Alias "GetSaveFileNameA" _
(pOpenfilename As OPENFILENAME) As Long
Private Declare Function GetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" _
(pOpenfilename As OPENFILENAME) As Long
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As Long
nMaxCustrFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustrData As Long
lpfnHook As Long
lpTemplateName As Long
End Type
Private Const OFN_ALLOWMULTISELECT = &H200
' otwiera okno dialogowe " Otwórz plik: " lub " Zapisz jako: " - tylko
wybór jednego pliku
' zwraca pełną ścieżkę pliku, po anulowaniu wyboru pliku zwraca ciąg
zerowej długości ""
Public Function zbDlgSaveOpenFileBis(fSave As Boolean, _
Optional hOwner As Long = 0, _
Optional sTitle As String = "", _
Optional sInitDir As String = "", _
Optional sFilter As String = "", _
Optional lFilterIndex As Long = 0, _
Optional lFlags As Long = 0) As String
Dim ofn As OPENFILENAME
With ofn
.hwndOwner = hOwner
.hInstance = 0
.lpstrInitialDir = sInitDir
If Len(sTitle) = 0 Then
If fSave Then
.lpstrTitle = " Zapisz jako: "
Else
.lpstrTitle = " Otwórz plik: "
End If
Else
.lpstrTitle = sTitle
End If
If Len(sFilter) = 0 Then
.lpstrFilter = "Wszystkie (*.*)" & vbNullChar & "*.*" & _
vbNullChar & vbNullChar
Else
.lpstrFilter = sFilter & vbNullChar
End If
.nFilterIndex = lFilterIndex
.nMaxFile = 260
.lpstrFile = String(.nMaxFile, vbNullChar)
.nMaxFileTitle = 260
.lpstrFileTitle = String(.nMaxFileTitle, vbNullChar)
If lFlags = 0 Then
If fSave = True Then
.flags = &HA080F
Else
.flags = &HA180D
End If
Else
.flags = lFlags
End If
' nie pozwól na wybór wielokrotny
If (lFlags And OFN_ALLOWMULTISELECT) = _
OFN_ALLOWMULTISELECT Then
.flags = .flags And (Not OFN_ALLOWMULTISELECT)
End If
' określ długość zmiennej
.lStructSize = Len(ofn)
If fSave = True Then
GetSaveFileName ofn
Else
GetOpenFileName ofn
End If
zbDlgSaveOpenFileBis = Left$(.lpstrFile, _
InStr(.lpstrFile, vbNullChar) - 1)
End With
End Function
' przykładowe wywołanie:
Private Sub btnPodepnijPdf_Click()
Dim sFilter As String
Dim sRet As String
sFilter = "Pliki pdf (*.pdf)" & vbNullChar & "*.pdf*" & vbNullChar & _
"Wszystkie (*.*)" & vbNullChar & "*.*" & vbNullChar
' okno dialogowe - " Zapisz jako: ""
'sRet = zbDlgSaveOpenFileBis(True, , , "C:\", sFilter)
' okno dialogowe - " Otwórz plik: "
sRet = zbDlgSaveOpenFileBis(False, , , "C:\Faktury\2018", sFilter)
If Len(sRet) = 0 Then
MsgBox "Anulowano"
Else
MsgBox sRet
Me!ScPliku = sRet
End If
End Sub
--
Pozdrowienia
BraZby
www.faq.accdb.pl
www.accdb.pl
Technical Details
Message-ID:
<p93ein$100$1@node2.news.atman.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mailReferences:
<42ca43b9-0cab-4dd0-b326-b07f93e382fd@googlegroups.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail From: Zbigniew Bratko <byle@co.pl> Newsgroups: pl.comp.bazy-danych.msaccess Subject: Re: Zapis ścieżki do pliku w polu tekstowym Date: Fri, 23 Mar 2018 18:46:56 +0100 Organization: ATMAN - ATM S.A. Lines: 151 Message-ID: <p93ein$100$1@node2.news.atman.pl> References: <42ca43b9-0cab-4dd0-b326-b07f93e382fd@googlegroups.com> NNTP-Posting-Host: 5.172.239.5 Mime-Version: 1.0 X-Trace: node2.news.atman.pl 1521827223 1024 5.172.239.5 (23 Mar 2018 17:47:03 GMT) X-Complaints-To: usenet@atman.pl NNTP-Posting-Date: Fri, 23 Mar 2018 17:47:03 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 In-Reply-To: <42ca43b9-0cab-4dd0-b326-b07f93e382fd@googlegroups.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit