Changing Paths

claddagh

Registered User.
Local time
Today, 15:01
Joined
Jun 15, 2005
Messages
63
Hello All,

I have a quick question that I cant seem to find the answer to in any of my books.

I have a line of code that I would like to change.
The code points to a default path of C:\My Documents\
Now, the problem is, that on some machines, windows is installed on G: for eg.

Code:
OpenFile.lpstrInitialDir = CDInitDir '"C:\My Documents"

Is there anyway that I can change the above line to "find" where the default install path for My Documents is ?

Many Thanks In Advance

Max
 
Look at the Windows Registry ---> WROX has good articles on how to access and work with the registry

CurDir("g") would get the default path of g
 
The Environ() function was made for stuff like that. Copy and past this for a quick test...

MsgBox Environ("USERPROFILE") 'C:\Documents and Settings\username
MsgBox Environ("windir") 'C:\WINDOWS
MsgBox Environ("USERNAME") 'network name
MsgBox Environ("COMPUTERNAME") 'name of users computer
MsgBox Environ("ALLUSERSPROFILE") 'C:\Documents and Settings\All Users

The last one is the way to go since the output files will be available to anybody who logs into the computer.
 
Will try this

ghudson,

Once again, thanks for the help.
Will try this out later and let you know how it went.

The thing that still confuses me is the reference to c:\
Different machines have differnt install drives, some are c:\ some are F:\ and some are G:\
God knows why this was done, but I have to compensate for someone elses mistakes. :)

Max
 
The Environ() should work for you. Good luck!
 
Another Prob

ghudson,

Still looking into the above, but i`ll test that later..
At the min, back to the archiving prob i had.
That code you gave me works a treat, but when i assign the switchboard button to run code, then module name.

When I run the form switchboard, and press the button to archive data, i get the following msg, "There was an error excecuting the command"

But if I run the code directly from the module panel in access, it runs fine.
Why does the switchboard throw up this error ????

TIA

Max
 
Claddagh, Environ() is good to use, but be careful when you start using it for other things. Different Operating Systems allow different parameters. However, I think the ones that Hudson gave you are universal to date with regards to the Windows OSs
 
Os

Modest,


We are only using the windows OS at the min here anyway, so that shouldn`t be a problem.
Thanks for the heads up
 
What I'm saying:
Environ() can take in other parameter strings that Hudson didn't list (they're easy to find and on this forum somewhere), which you may come across some time.

I'm just giving you a heads up that not all versions of Windows OS (98,2000,ME,XP,2003,etc) use the same parameters. If your database is to be cross-platform, you should double check each of these, though I think the ones he listed can be used by all versions of windows.

Again this is just a forewarning if you choose to use Environ() for other functionalities
 
I do not mess with the switchboard manager for forms. I use a custom main menu to avoid the limitations of the built-in switchboards (Pat Hartman loves them but to each thier own ;-)

What is the code you are using in your forms OnCLick event to run the Environ function.

Also, the Environ function will give consistant results if you use the "string" parameter not the numerical parameter like i listed above. That is what modest was talking about.
 
I dont like using switchboard, because it's ugly. I would rather make my own switchboard :)

Additionally, I use an invisible opening form that tracks the user logged into the database by storing it in a table... that form opens the main form. When the main form is closed, the application is closed and the that user is removed from the table.

This way I can easily see who is logged in and who isn't. I realize I could use the jet roster, but when new users use the database, I have a form for them to type in their name. That way if I need someone out I'll know who it is and I can ask them without forcing them out :)

Moral of the story:
I don't like using the switchboard
 
Switchboard

Modest,

I too myself am not too keen on the switchboard, I find it a little bit on the limited side, but not being that clued up on access, I have no choice at the min, as its easy to implemet and use mainly.


Once I have the knowledge and the time, the first thing to go will be just that. (edit::[Just picked up a book to learn this :) so soon be gone ])

Ghudson,

I dont have an onclick event as you speak of, I have used the wizard in the switchboard manager to call the module. (see pic attached )

TIA

Max
 

Attachments

  • switchboard.jpg
    switchboard.jpg
    66.2 KB · Views: 182
Last edited:
"mod_archive_data" is the name of the module, you must call the actual function.

Ensure that your code is in a public [not a class] module and you are calling a Public Function xxx () not a Sub xxx () and not a module.

I do not use the switch board [for many reasons like your example] so the above is a logical guess.
 
Confused.

ghudson,

I thought the module WAS the function, guess i was wrong.
I`ll have a look through my books and see what they say about calling functions.

Thanks for the advice..

Max

[UPDATE]

The code is as below

Code:
Option Compare Database

Function [B]mcr_archive_data[/B]()
On Error GoTo mcr_archive_data_Err

    Beep
    If MsgBox("ARE YOU SURE YOU WANT TO ARCHIVE SELECTED DATA?", vbQuestion + vbYesNo, "Archive Data") = vbYes Then
        DoCmd.Hourglass True
        DoCmd.SetWarnings False
        DoCmd.OpenQuery "qry_archive_data", acViewNormal, acEdit
        MsgBox "Copying Data To Archive Table Complete", vbInformation, "Copying Data"
        DoCmd.OpenQuery "qry_delete_archive_cust_data", acVireNorman, acEdit
        MsgBox "Deleting Old Data From Customer Table Complete", vbInformation, "Deleting Old Customer Data"
        DoCmd.SetWarnings True
        DoCmd.Hourglass False
        Beep
        MsgBox "Archiving Data Completed Successfully.", vbInformation, "Archiving Data Msg"
    Else 'user clicked No
        Beep
        MsgBox "Archiving Aborted", vbInformation
    End If
    
mcr_archive_data_Exit:
    DoCmd.SetWarnings True
    DoCmd.Hourglass False
    Exit Function

mcr_archive_data_Err:
    MsgBox Err.Number & " - " & Err.Description
    Resume mcr_archive_data_Exit

End Function

So the Function name would be the section highligted in bold right ???

Just want to make sure.

Max
 
Last edited by a moderator:
Works now

ghudson,

did what you said, called the function, as names in the above post, and now that i have done that it works a treat.

Thanks for pointing me in the right direction.

Max
 
Another satisfied customer. :)

Although I disagree with your naming convention. Functions and subs are not macros, so I would avoid the mcr_ prefix. Just name it "Public Function Archive_Data()".

FYI, never give a module the same name as a function or sub for that will cause problems.
 
Couple of comments here. I like Switchboards too. I don't find then either ugly (though that is a matter of taste) or limiting. I've dressed up my switchboards with different coloring schemes, different graphics, different titling etc. I've customized them to restrict access to certain features.

The key about the Access Switchboards is that they are based on a table of value. This makes them very flexible because you can manipulate the functions based on the values. For example, I often add a field to the Switchboard Items table called Level. It will contain values like Admin, Editor, Reader. I then compare the access level of the option with the access level of the user to determine whether they can use that particlular function. This is done in the HandleButtonClick() function generated when the Switchboard is created.

My point is that Switchboards don't have to be ugly because you can dress them up. Nor do they have to be limiting because you can customize the code.
 
ScottGem said:
Couple of comments here. I like Switchboards too...

The key about the Access Switchboards is that they are based on a table of value. This makes them very flexible because you can manipulate the functions based on the values...

My point is that Switchboards don't have to be ugly because you can dress them up. Nor do they have to be limiting because you can customize the code.
Modest said:
I would rather use my own switchboard
I pre-answered what you just posted. First of all, if you're customizing theirs, you're making your own. I just prefer to make mine from scratch, instead of building mine on "crap" because, well, these templates/wizards Access provides are crap. They're meant for beginners who don't know what they're doing, that is why I don't think they've changed since A97.
 
modest said:
I pre-answered what you just posted. First of all, if you're customizing theirs, you're making your own. I just prefer to make mine from scratch, instead of building mine on "crap" because, well, these templates/wizards Access provides are crap. They're meant for beginners who don't know what they're doing, that is why I don't think they've changed since A97.

Well you do have a point that by customizing you are making your own. I'll also concede that some of what Access does for you in wizards is "crap" (one glaring example is the Form wizard using field names for control names).

I just happen to think that the code generated by the Switchboard Manager is pretty decent and provides a good deal of flexibility.
 

Users who are viewing this thread

Back
Top Bottom