I'm using Access 2000 on Windows 7, and have been following numerous examples of how to create a "Browse for file" button which displays the path of the file in a text box.
This is as close as I have come to finding a solution, and yet I have an error with the line highlighted in bold below.
The error states: Compile Error:
Method or Data Member not found
Can anyone explain what might be causing the problem?
My code is found below: - Private Sub fdg_Click()
-
-
Dim fdg As FileDialog, vrtSelectedItem As Variant
-
Dim strSelectedFile As String
-
- Set fdg = Application.FileDialog(msoFileDialogFilePicker)
-
With fdg
-
.AllowMultiSelect = False
-
.InitialView = msoFileDialogViewDetails
-
If .Show = -1 Then
-
For Each vrtSelectedItem In .SelectedItems 'onby be 1
-
strSelectedFile = vrtSelectedItem & "#" & vrtSelectedItem
-
Next vrtSelectedItem
-
Me![txtSelectedFile] = strSelectedFile
-
Else 'The user pressed Cancel.
-
End If
-
End With
-
-
Set fd = Nothing
-
-
End Sub
Many thanks!
11 3970
I believe that your problem is in line 19. You have
However, the variable that you defined was fdg. Try that and see what you get.
NeoPa 32,556
Expert Mod 16PB
Line #19 certainly is a problem, but the highlighted line (which was obscure before as BOLD tags don't show well within CODE tags) is the problem asked about (and Smiley's response deals with that).
Good work both of you :-)
A problem can be (I am not sure) line 3. You already have a control named "fdg". I see that in line 1.
NeoPa 32,556
Expert Mod 16PB
Not a compile problem certainly, but just as certainly an unwise choice when programming (and worth pointing out). Both can still be referenced, but any reference will be ambiguous to a reader if not the VBA interpreter (which is not good news).
- The Code you displayed is for Copying an Absolute File Path to a Text Box, whose Control Source is a Hyperlink Field. I do not think that this is what you want, since you did not specifically mention it.
- The Code can be made shorter and more efficient, as in:
- Dim fdg As FileDialog
-
-
'Must set a Reference to the Microsoft Office ?X.X Object Library
-
Set fdg = Application.FileDialog(msoFileDialogFilePicker)
-
-
With fdg
-
.AllowMultiSelect = False
-
.InitialView = msoFileDialogViewDetails
-
If .Show = -1 Then
-
Me![txtSelectedFile] = .SelectedItems(1)
-
End If
-
End With
-
-
Set fdg = Nothing
NeoPa 32,556
Expert Mod 16PB
And (Just to be competitive with ADezii :-D) you can tidy it even further (than the good job he's already done). - 'Must set a Reference to the Microsoft Office XX.X Object Library
-
With Application.FileDialog(msoFileDialogFilePicker)
-
.AllowMultiSelect = False
-
.InitialView = msoFileDialogViewDetails
-
If .Show Then Me.txtSelectedFile = .SelectedItems(1)
-
End With
When you're done though Gwyn, I would suggest post #3 as a good candidate for Best Answer.
NB. ADezii's post gives a good approach to dealing with code that has library dependencies too. It is a very good idea to include such a comment line whenever any of your code depends on any libraries that are not referenced as standard.
Apologies for the late reply, thank you all for your answers. Smiley: I had already referenced it, but I wonder whether these objects that are referenced might be causing an issue:
- Microsoft Access 9.0 Object Library (is there a MS Access/Windows 7 conflict?)
- MISSING: Core OLE Control Module (is this important?) ADezii/NeoPa: Apologies I'm not the best at VBA. The purpose of this is for users to search folders for image or text files, then select them leaving behind a hyperlink to open that file.
Do your codes meet this requirement? I noticed ADezii has posted about this very clearly in the past, but for some reason I could not get that code to work, and I wonder whether the references I'm using are the issue.
The only External Reference needed to get the Code to work is the Microsoft Office ?X.X Object Library.
I am not sure if this code is what you are looking for.
To try, paste it in a global module, make necessary changes (especially in sFilter) and apply from where you need.
The code will open the common dialog for "Open File" using API interface, so you don't need to reference any library. - Option Compare Database
-
Option Explicit
-
-
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 String
-
nMaxCustFilter 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
-
lCustData As Long
-
lpfnHook As Long
-
lpTemplateName As String
-
End Type
-
-
Public Function SelectFile(StartFolder As String) As String
-
Dim OpenFile As OPENFILENAME
-
Dim lReturn As Long
-
Dim sFilter As String
-
OpenFile.lStructSize = Len(OpenFile)
-
' OpenFile.hwndOwner = strform.Hwnd
-
sFilter = "Access 2003 (*.mdb)" & Chr(0) & "*.mdb" & Chr(0) & _
-
"Access 2007 (*.accdb)" & Chr(0) & "*.accdb" & Chr(0)
-
OpenFile.lpstrFilter = sFilter
-
OpenFile.nFilterIndex = 1
-
OpenFile.lpstrFile = String(257, 0)
-
OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
-
OpenFile.lpstrFileTitle = OpenFile.lpstrFile
-
OpenFile.nMaxFileTitle = OpenFile.nMaxFile
-
OpenFile.lpstrInitialDir = "StartFolder"
-
OpenFile.lpstrTitle = "Select a file using the Common Dialog DLL"
-
OpenFile.flags = 0
-
lReturn = GetOpenFileName(OpenFile)
-
If lReturn = 0 Then
-
MsgBox "A file was not selected!", vbInformation, "Select a file using the Common Dialog DLL"
-
Else
-
SelectFile= Trim(Left(OpenFile.lpstrFile, InStr(1, OpenFile.lpstrFile, vbNullChar) - 1))
-
End If
-
End Function
Good luck ! NeoPa 32,556
Expert Mod 16PB
The code blocks suggested enable you to provide the browsing facility for the user and have a string value which is the address of the file chosen. What you do with it from there is down to you, but if you want help with something in particular then I'm sure posting a question about it would work for you (Not in here though as each thread must be about the single original question only). There is already an existing thread that covers the same ground though ( Error 7980: HyperlinkAddress or HyperlinkSubAddress read-only for Hyperlink).
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Wayne |
last post by:
The following which is driving me nuts has occurred in 2 of my
databases. Both databases were written in Access 2003 and then
converted back to Access 2000 format. I've done this so I can create an...
|
by: MLH |
last post by:
A97 aborts creation of MDE reporting that there's a compile
error in one form. Sure enough, if I remove the form from the
source database and attempt to compile the MDE, it succeeds.
But when I...
|
by: Darren |
last post by:
Hi,
I have a command button which has a macro running in it.
The macro on the click event, runs to ensure that certain values in a
form are valid, (e.g. the textboxes are not null)
and...
|
by: Larry Epn |
last post by:
I've created a project from Microsoft's "club.vsi". I don't want inline code
so I've separated all aspx and ascx pages into code-behind pages. I'm
compiling the project and continue to get this...
|
by: petekikamookow |
last post by:
Hi Guys.........Help Please
I'm trying to add a password to limit access to a command button called"Confidential Information"
Mucho regardo
|
by: cnixuser |
last post by:
Hi, I am working on a class assignment, and I am receiving an error, that has me stumped. In the assignment I am trying to bind a datagrid control to an Access Database. When I compile the Web...
|
by: joemo2003 |
last post by:
Need help, please!
In an excel vba automation, in my code have some codes like "Global vsapp as visio.application", but in some other computer don't have visio installed, and i won't use that visio...
|
by: blakerrr |
last post by:
Hi everyone,
I am trying to export a table to an excel file using vba on a form's button click event. I am getting the error:
Compile error: User-defined type not defined.
And it highlights...
|
by: falroc |
last post by:
I created a Access 2007 database that had a add record command button that worked just fine until I split the database and made Sqlexpress 2005 the backend. Now, when I click on the add record...
|
by: alnino |
last post by:
Hi,
On a form I have a command button that allows a user to browse for a file (PDF, Word, etc…). This command button then stores a hyperlink to the file within an associated txtfield in the table....
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |