Solved

Common  Dialogs

Posted on 1998-03-30
10
345 Views
Last Modified: 2008-02-01
Chapter 19 of the Access 97 Developer's Handbook (by Litwin, Getz, and Gilbert) provides a very useful function called adhOfficeGetFileName along with a demostration form called frmOfficeFileOpen in ch19.mdb. There is one very desirable feature that I just can't seem to get to work. No matter what I do, adhcGfniNoChangeDir doesn't seem to have any effect one way or the other.

If my current directory is c:\abc and I call adhcOfficeGetFileName, I start looking in c:\abc as I expected. If I use adhOfficeGetFileName to "open" a file in c:\def, I want the next call to adhOfficeGetFileName to start looking in c:\def, and not stay in c:\abc. How can I get this function to "remember" the last directory used?

I also noticed that when I open ch19.mdb I get a message "This database is read only ..." How can I set one of my databases to be read only?

Thanks
0
Comment
Question by:rmk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 12

Expert Comment

by:Trygve
ID: 1972473
This could be solved by using a global variable. If you like you could send me an extract of your database including the functions, forms, tables etc. involved and I will be glad to have a look at it. EMail: kontry@statoil.no

For your last question; There are several ways of doing this. For the ch19.mdb my guess is that this database has been copied from a CD onto your harddisk. All CD files are read only and will stay this way untill you change it. Locate your mdb file using the explorer and right click on it. Select properies and mark the Read-only attribute. Your users will of course be able to do the same trick in reverse, so if you want to secure your database in a more bulletproof manner you should have a look at the security wizard. I can also send you 3 files on Access security if you want, just provide me with your email address.
0
 
LVL 3

Expert Comment

by:guillems
ID: 1972474
1. There's a way to know the current directory in any drive. This is

  CurDir [Drive]

This give you the current dir.

2. The second way is to see that Trygve say (the properties of the file)

I hope this help you

0
 
LVL 12

Expert Comment

by:Trygve
ID: 1972475
guillems: The problem is probably that locating files using these special functions does not change the current directory. It remaing c:\abc. An I must once again say that you are pushing it adding so little new information and calling it an answer. grrr.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:guillems
ID: 1972476
Excuse moi! Trygve! I just try to help. I don't think I doing anything wrong. I'm free to do that I want. So Please I think that you must say  pardon!

Have a nice day!

0
 
LVL 12

Expert Comment

by:Trygve
ID: 1972477
rmk: I have tried to locate ch19.mdb on the net to examine it, but i can't find a copy. My offer to look at your application still stands.

guillems: If you got offended by my comment, then I appologize.
You have to admit though, that a five line answer to a 500 points questions seems a bit to easy. Especially when half the answer is a repetition of my comment.

Of course, you are free to do what you want, but this goes both ways. If you really feal that your answer qualifies as an answer, then please let me know, so I can adjust my personal opinion of what it takes to lock a question.

Have a pleasant day at E-E
Trygve
0
 
LVL 3

Expert Comment

by:guillems
ID: 1972478
Sometimes the solution is simple, There's no problem with this. Just there are people who don't see the easy and beaty of the simple things.

Have a nice Day!
0
 

Author Comment

by:rmk
ID: 1972479
I guess I was mistakenly under the impression that all serious Access developer's were familiar with the "Access 97 Developer's Handbook". I would really appreciate some input from anywone who has used adhOfficeGetFileName.

Thanks
0
 
LVL 12

Accepted Solution

by:
Trygve earned 500 total points
ID: 1972480
I myself use books only for reference these days. In my shelf I have "Access 97 Power Programming", "Access and SQL Server" and "teach yourself Transact-SQL in 21 days".

I find answers to most of my questions using CDs from Microsofts Developer Network.

OK, I had a look at the function and there are several ways of doing this; Extending the type to include a LastDir property, using a globally defined gfni and what I did, using a globally defined LastDir variable. Here is the contents of my test module:


Option Compare Database
Option Explicit

' Set LastDir as a global variable
Global LastDir As String

Function TestGetFileName()

' From Access 97 Developer's Handbook
    ' by Litwin, Getz, and Gilbert (Sybex)
    ' Copyright 1997.  All rights reserved.
   
    Dim gfni As adh_accOfficeGetFileNameInfo
    With gfni
        .hwndOwner = Application.hWndAccessApp
        .strAppName = "Delete Extra HTML"
        .strDlgTitle = "Select an HTML File"
        .strOpenTitle = "Select"
        .strFile = ""
        ' Set the Last directory as initial directory for the file.
        .strInitialDir = Nz(LastDir)
        .strFilter = "HTML (*.html;*.htm)|HTM Files (*.htm)|HTX Files (*.htx)|All Files (*.*)"
        .lngFilterIndex = 1
        .lngView = adhcGfniViewList
        .lngFlags = adhcGfniNoChangeDir Or adhcGfniInitializeView
    End With
    If adhOfficeGetFileName(gfni, True) = adhcAccErrSuccess Then
        MsgBox "You chose: " & Trim(gfni.strFile), vbOKOnly, "Test Get File Name"
        ' Get the complete path to the selected file
        LastDir = gfni.strFile
        ' Remove one character at a time from the right till a \ is found
        Do Until Right(LastDir, 1) = "\"
            LastDir = Left(LastDir, Len(LastDir) - 1)
        Loop
        ' Then remove the \
        LastDir = Left(LastDir, Len(LastDir) - 1)
        ' Show the directory path for the selected file.
        MsgBox ("The selection is located in " & LastDir)
    End If
   
End Function


This seemed to work perfectly in my test app. It will of cource reset itself every time you restart your app, but this is another problem that could also be solved by some ini-file programming or having a table with the users and their last selections in it.

Please let me know if you need more.

Trygve
0
 

Author Comment

by:rmk
ID: 1972481
Thanks for your response.
0
 
LVL 12

Expert Comment

by:Trygve
ID: 1972482
Hey rmk. Thanks for accepting my answer !

You should have a look at your customer information. It seems to me that you have posted an answer as your personal details.

Have a nice day !
Trygve
0

Featured Post

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question