Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rating: Thread Rating: 7 votes, 5.00 average. Display Modes
Old 01-06-2016, 07:50 AM   #1
radek225
Newly Registered User
 
Join Date: Apr 2013
Posts: 307
Thanks: 75
Thanked 0 Times in 0 Posts
radek225 is on a distinguished road
Filter in msoFileDialogSaveAs

have a function that shows me the saving path choosen by user
The problem is I can't set filter to *accdb. If I work with msoFileDialogFilePicker then .filter property works. What should I do to set filter *accdb in msoFileDialogSaveAs?

Code:
Function Plik(TytulOkna As String, TytulPrzycisku As String, Filtr As String) As String
    Dim wskazMiejsce As FileDialog
    Set wskazMiejsce = Application.FileDialog(msoFileDialogSaveAs)
    wskazMiejsce.Title = TytulOkna
    wskazMiejsce.ButtonName = TytulPrzycisku
    wskazMiejsce.AllowMultiSelect = False
    wskazMiejsce.InitialFileName = "wniosek.accdb"
    If wskazMiejsce.Show = -1 Then
        WskazPlik = wskazMiejsce.SelectedItems(1)
        MsgBox WskazPlik
    End If
End Function

radek225 is offline   Reply With Quote
Old 01-06-2016, 08:14 AM   #2
Ranman256
Newly Registered User
 
Join Date: Apr 2015
Location: KY,USA
Posts: 3,335
Thanks: 0
Thanked 735 Times in 720 Posts
Ranman256 will become famous soon enough Ranman256 will become famous soon enough
Re: Filter in msoFileDialogSaveAs

.Filters.Add "Images", "*.gif; *.jpg; *.jpeg", 1
Ranman256 is offline   Reply With Quote
Old 01-06-2016, 08:22 AM   #3
cyanidem
Nieˇhfytny jaszczomp
 
Join Date: Nov 2015
Location: Consett, UK
Posts: 106
Thanks: 5
Thanked 26 Times in 25 Posts
cyanidem is on a distinguished road
Re: Filter in msoFileDialogSaveAs

You can't directly set filters on msoFileDialogSaveAs.
However if you set the InitialFileName to *.accdb then dialog will force that extension. The filter will still say "All Files" but it will not show files with different extensions.

cyanidem is offline   Reply With Quote
Old 01-06-2016, 08:40 AM   #4
radek225
Newly Registered User
 
Join Date: Apr 2013
Posts: 307
Thanks: 75
Thanked 0 Times in 0 Posts
radek225 is on a distinguished road
Re: Filter in msoFileDialogSaveAs

Quote:
Originally Posted by cyanidem View Post
You can't directly set filters on msoFileDialogSaveAs.
However if you set the InitialFileName to *.accdb then dialog will force that extension. The filter will still say "All Files" but it will not show files with different extensions.
Why? When you saving some file e.g. from ms office filter is on

you mean wskazMiejsce.InitialFileName = "*.accdb"? - doesn't work. I still see another files
radek225 is offline   Reply With Quote
Old 01-06-2016, 08:56 AM   #5
cyanidem
Nieˇhfytny jaszczomp
 
Join Date: Nov 2015
Location: Consett, UK
Posts: 106
Thanks: 5
Thanked 26 Times in 25 Posts
cyanidem is on a distinguished road
Re: Filter in msoFileDialogSaveAs

Why? Because MS says so here: https://msdn.microsoft.com/en-us/lib...ffice.10).aspx

Quote:
Note A run-time error will occur if the Filters property is used in conjunction with the Clear, Add, or Delete methods when applied to a Save As FileDiaog object. For example, Application.FileDialog(msoFileDialogSaveAs).Filter s.Clear will result in a run-time error.
cyanidem is offline   Reply With Quote
Old 01-06-2016, 09:01 AM   #6
radek225
Newly Registered User
 
Join Date: Apr 2013
Posts: 307
Thanks: 75
Thanked 0 Times in 0 Posts
radek225 is on a distinguished road
Re: Filter in msoFileDialogSaveAs

Quote:
Originally Posted by cyanidem View Post
Ok, what about InitialFileName, how should i set it correctly to have *accdb?
radek225 is offline   Reply With Quote
Old 01-06-2016, 09:01 AM   #7
Frothingslosh
Premier Pale Stale Ale
 
Frothingslosh's Avatar
 
Join Date: Oct 2012
Location: Flint, Michigan, USA
Posts: 3,200
Thanks: 82
Thanked 453 Times in 411 Posts
Frothingslosh will become famous soon enough Frothingslosh will become famous soon enough
Re: Filter in msoFileDialogSaveAs

There's always the API: http://access.mvps.org/access/api/api0001.htm

__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Frothingslosh is offline   Reply With Quote
Old 01-07-2016, 03:37 AM   #8
cyanidem
Nieˇhfytny jaszczomp
 
Join Date: Nov 2015
Location: Consett, UK
Posts: 106
Thanks: 5
Thanked 26 Times in 25 Posts
cyanidem is on a distinguished road
Re: Filter in msoFileDialogSaveAs

Quote:
Originally Posted by radek225 View Post
you mean wskazMiejsce.InitialFileName = "*.accdb"? - doesn't work. I still see another files
Yes, that. And it works for me, I can see only accdb files and "Save as type" shows "All files (*.*)"
cyanidem is offline   Reply With Quote
Old 01-07-2016, 11:07 PM   #9
radek225
Newly Registered User
 
Join Date: Apr 2013
Posts: 307
Thanks: 75
Thanked 0 Times in 0 Posts
radek225 is on a distinguished road
Re: Filter in msoFileDialogSaveAs

Quote:
Originally Posted by cyanidem View Post
Yes, that. And it works for me, I can see only accdb files and "Save as type" shows "All files (*.*)"
Could you show me your sample?
radek225 is offline   Reply With Quote
Old 01-08-2016, 01:01 AM   #10
cyanidem
Nieˇhfytny jaszczomp
 
Join Date: Nov 2015
Location: Consett, UK
Posts: 106
Thanks: 5
Thanked 26 Times in 25 Posts
cyanidem is on a distinguished road
Re: Filter in msoFileDialogSaveAs

My sample is exactly your sample. Only thing I had to do is declare WskazPlik variable as it's not in your function.
Code:
 
Public Function Plik(TytulOkna As String, TytulPrzycisku As String, Filtr As String) As String
    Dim wskazMiejsce As FileDialog
    Dim WskazPlik As Variant
    Set wskazMiejsce = Application.FileDialog(msoFileDialogSaveAs)
    wskazMiejsce.Title = TytulOkna
    wskazMiejsce.ButtonName = TytulPrzycisku
    wskazMiejsce.AllowMultiSelect = False
    wskazMiejsce.InitialFileName = "*.accdb"
'    wskazMiejsce.Filters.Item(0) = "*.accdb"
    If wskazMiejsce.Show = -1 Then
        WskazPlik = wskazMiejsce.SelectedItems(1)
        MsgBox WskazPlik
    End If
End Function
 
Private Sub Command0_Click()
Dim nazwa As String
    nazwa = Plik("title", "zapisaj", "*.accdb")
End Sub
And as you can see below it shows only accdb files:

savefiledialog.jpg

cyanidem is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] command button: set a default filter & filter on load rodrigoturbina Forms 17 08-13-2014 07:58 AM
Filter Records: Adding unbound Date listbox to Filter String mactheknife Modules & VBA 2 02-10-2014 08:19 AM
Dynamically filter form - filter property too long cpberg1 Modules & VBA 5 05-29-2012 02:14 AM
Loading a Filter with a report Using the Form's Filter Property Line Item catbeasy Reports 2 07-08-2009 07:41 AM
Filter Form; If no record found turn filter off question rotteneggz Modules & VBA 6 03-19-2009 05:32 PM




All times are GMT -8. The time now is 05:02 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World