Office & Productivity Software forum

General discussion

Access 2002 VB Code Question

by boomer32 / March 17, 2004 1:45 AM PST

I copied some code from the northwind database to my new database. I developed a form like the employees form in northwind db the code for the add/change and remove buttons is what i copied ....no other code was in my db on my form I started fresh...well the code that i copied is all the code in the employees form for all the events needed. well i go to run my form and push the add/change button and the compile error comes up with the (variable not defined error) Here is the variable it talks about not being defined(msoFileDialogFilePicker) here is the code... How Do I define the variable???

Sub getFileName()
' Displays the Office File Open dialog to choose a file name
' for the current employee record. If the user selects a file
' display it in the image control.
Dim fileName As String
Dim result As Integer
With Application.FileDialog(msoFileDialogFilePicker)
.Title = "Select Employee Picture"
.Filters.Add "All Files", "*.*"
.Filters.Add "JPEGs", "*.jpg"
.Filters.Add "Bitmaps", "*.bmp"
.FilterIndex = 3
.AllowMultiSelect = False
.InitialFileName = CurrentProject.path
result = .Show
If (result <> 0) Then
fileName = Trim(.SelectedItems.Item(1))
Me![ImagePath].Visible = True
Me![ImagePath].SetFocus
Me![ImagePath].Text = fileName
Me![FirstName].SetFocus
Me![ImagePath].Visible = False
End If
End With
End Sub

thanks in advance

John

Discussion is locked
You are posting a reply to: Access 2002 VB Code Question
The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our CNET Forums policies for details. All submitted content is subject to our Terms of Use.
Track this discussion and email me when there are updates

If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.

You are reporting the following post: Access 2002 VB Code Question
This post has been flagged and will be reviewed by our staff. Thank you for helping us maintain CNET's great community.
Sorry, there was a problem flagging this post. Please try again now or at a later time.
If you believe this post is offensive or violates the CNET Forums' Usage policies, you can report it below (this will not automatically remove the post). Once reported, our moderators will be notified and the post will be reviewed.
Collapse -
Re:Access 2002 VB Code Question
by Kees Bakker / March 17, 2004 5:49 AM PST

This looks very professional. I don't have Access 2002, so I can't look it up. Some hints to help you find it yourself, maybe:
- Check the whole module you copied this sub from for the define (dim mso.. as ....). Variables can be defined outside subroutines.
- Or it might be a global variable, defined by some module, to be found in the module tab. But I think the first is the more likely.
- Check the help for FileDialog action of Application-object. This might give an example and an explanation.

I think somebody else will come along with the full answer, but this may help you in the mean time.

Hope this helps.

Kees

Collapse -
Re:Access 2002 VB Code Question
by Kees Bakker / March 17, 2004 4:51 PM PST

John,

This is very strange. The documentation is clear and it doesn't work here either.
See also:
http://support.microsoft.com/default.aspx?scid=kb;en-us;279508 (and 824272, 288543, 282335).

Note: you might find http://support.microsoft.com/default.aspx?scid=kb;en-us;282384 interesting also (it's about quality of pictures).

This is a predefined value for Dialogtype, with these allowed values:
msoFileDialogFilePicker
msoFileDialogFolderPicker
msoFileDialogOpen
msoFileDialogSaveAs

However, if I type in
Application.filedialog (
I get a popupwindow with only the last 3 items mentioned, and not the first, while it seems to work in Northtwind (or does it? make a copy of the database, and try to compile it).

Some possible solutions:
- Contact Microsoft support. It's a clearcut question, and they should be able to give you an answer or a patch. Point them to this discussion if you can't explain it by telephone.
- These predefined values tend to be just 0,1,2,3,4, or 0,1,2,4,8. So try 0 or 1 in stead of the symbolic name msofiledialogfilepicker. You can see what the value of the other is by just using them and having a look at the resulting value of dialogtype in the debug-window.
- See if you can use msoFileDialogOpen, which does pop up, so is supposed to work. It will have different properties, but might return the filename of 1 chosen file, which might be what you need (filepicker picks more than 1).

As a last resort, there are workarounds by using the code that worked in earlier versions of MS Access (and still works). If necessary, I can provide links to examples.

Hope this helps, and wait for Danny.


Kees

Collapse -
Re:Re:Access 2002 VB Code Question
by boomer32 / March 18, 2004 10:55 PM PST

Kees,
Thanks so much I looked through all you posted and it helped greatly I did get it to work but I am not sure how. I am back at it today and will let you know...by the way what time zone are you on...I am central time zone its 8:54 am as I am typing this post...any thanks again....

John

Collapse -
(NT) CET (Central European) = GMT - 1. It's 9 hours later here than PST.
by Kees Bakker / March 19, 2004 2:19 AM PST

.

Collapse -
Re: Access 2002 VB Code Question
by davidlandy / November 10, 2004 7:41 PM PST

John,

The "correct" way of doing this is as follows:

First, you need to include a reference to the Microsoft Office 10.0 Type Library.

To do this, open a code module, then - in the Visual Basic editor - click on Tools|References, then scroll down and check "Microsoft Office 10.0 Object Library".

Now you can add the following lines to your code:

Dim dlgType As MsoFileDialogType
dlgType = msoFileDialogFilePicker 'or whatever

And then call the file dialog like this:

With Application.FileDialog(dlgType)

When you set the dlgType you will get a drop-down list, showing all possible settings for this value.

To summarise, your sub should now start like this:

Sub getFileName()
' Displays the Office File Open dialog to choose a database
Dim FileName As String
Dim result As Integer
Dim dlgType As MsoFileDialogType
dlgType = msoFileDialogFilePicker: Debug.Print dlgType

With Application.FileDialog(dlgType)
.Title = "Select Database"

'etc

Hope this helps.

David.

PS. The quick "hack" way around this is to use numeric constants in place of the dlgType variable. This saves you having to include a reference to the MS Office Type Library, and saves declaring the extra variable.

The downside is your code is less readable and less maintainable.

If you want to go this route, the constant values are:

msoFileDialogOpen = 1
msoFileDialogSaveAs = 2
msoFileDialogFilePicker = 3
msoFileDialogFolderPicker = 4

So you can just call

With Application.FileDialog(1) 'or 2, 3, or 4

Popular Forums
icon
Computer Newbies 10,686 discussions
icon
Computer Help 54,365 discussions
icon
Laptops 21,181 discussions
icon
Networking & Wireless 16,313 discussions
icon
Phones 17,137 discussions
icon
Security 31,287 discussions
icon
TVs & Home Theaters 22,101 discussions
icon
Windows 7 8,164 discussions
icon
Windows 10 2,657 discussions

CNET FORUMS TOP DISCUSSION

Help, my PC with Windows 10 won't shut down properly

Since upgrading to Windows 10 my computer won't shut down properly. I use the menu button shutdown and the screen goes blank, but the system does not fully shut down. The only way to get it to shut down is to hold the physical power button down till it shuts down. Any suggestions?