If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Unanswered: API File Open/Save dialog box - Again?!?!?!?!

Hi,
I am really sorry to bore everybody, but I have been struggling with this for the past couple of months (I have given up a few times in between).

I am working on a very simple database for myself. All of the stuff is very basic except for one function which I really need but I can't get it to work. It has been covered here many times but I just don't get it.

What I need is:
- A Command Button which opens API Open/Save with ‘multiple’ or at least ‘single’ File selection option.

- These Files (Links) are then saved in a List Box or Combo Box

- When I click on one of the Files (Links) in the List /Combo Box, it should open up in the correct application. (Tried 'ShellExecute' but couldn't get it to work)

- If at all possible, a 'delete' function to get rid of Files (links) that are out of date.

This is it. Probably nothing complicated for most of you, but caused me endless headaches and sleepless nights.

Attached a db file so you can see how far I've got. Please keep in mind that I have no clue about VBA programming. You really need to explain it to me step by step.

Tried it

Hi Tanis,

I've tried this one many times before. All previous posts about this subject suggested this link but I can't get it to work. Only thing I ever got to work in VBA is the one I have used in my attachment and that was only because somebody was nice enough to explain Step-By-Step what to do. I sit in front of the codes and haven't got a clue what any of it means. Don’t even know what exactly a module or a class module is and how they are related to the 'Click' function.

Type tagOPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
strFilter As String
strCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
strFile As String
nMaxFile As Long
strFileTitle As String
nMaxFileTitle As Long
strInitialDir As String
strTitle As String
Flags As Long
nFileOffset As Integer
nFileExtension As Integer
strDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

' The function call filled in the strFileTitle member
' of the structure. You'll have to write special code
' to retrieve that if you're interested.
If fResult Then
' You might care to check the Flags member of the
' structure to get information about the chosen file.
' In this example, if you bothered to pass in a
' value for Flags, we'll fill it in with the outgoing
' Flags value.
If Not IsMissing(Flags) Then Flags = OFN.Flags
ahtCommonFileOpenSave = TrimNull(OFN.strFile)
Else
ahtCommonFileOpenSave = vbNullString
End If
End Function

Function ahtAddFilterItem(strFilter As String, _
strDescription As String, Optional varItem As Variant) As String
' Tack a new chunk onto the file filter.
' That is, take the old value, stick onto it the description,
' (like "Databases"), a null character, the skeleton
' (like "*.mdb;*.mda") and a final null character.

I tried to open your zip file, but I think it must be Access2000. So, here is a step by step guide to use the code as I have used it in Access 97

1. Open your db in design mode
2. Create a new module by clicking on the module tab then New.
3. Copy and paste the code from the dev ashish site in its entirety into the module.
4. Create an unbound form with one text box and three command buttons.
5. One button will open the file. One button will cancel the operation and one button will browse.
6. Place this code behind the open file button.

So I thought I must have done something wrong again and tried yours. Now that worked like a dream and is exactly what I wanted.
Problem started though when I tried to copy the codes and things into my db. I am now getting exactly the same error message as I did with David's.

Here is your file back. I got it to work but had to remove some of your references. I'm not sure why, but something was confusing vb. Look through it and see what references were removed. You can add them back and then test each time to see which one causes the error. Sometimes just changing the order of importance can fix the problem so you may be able to add them back with no problem.

Many thx. OpenSaveFile is working like a treat now.
Have another problem with the OpenSaveFile though which I hadn't anticipated. I need to have MANY "Histories" (which includes the OpenFile Txtbox) under ONE "Company" (This is the main Form of which the "History" Form is the subform). What is happening at the moment is that I can create multiple "History" records except for the paths saved in the OpenSaveFile. The Paths in there stay the same, whatever "History" Record I call up.