MS Access replace part of file name with current directory - sql

I'm trying to use MS Access to make a simple database of the store I work in and I have to insert photo's and I'm doing so by having a column where the filepath is stored eg. "C:\User\WL\Documents\Databasefolder\Pictures\img_xxxx.jpg" but when I hand over the file to my boss, the filename will be wrong as he will put it in a different folder.
So I'm looking for somekind of function that changes the "C:\User\WL\Documents\Databasefolder" to the current directory of the database with included pictures. I have almost no experience with SQL or Access alltogether, hence I came here.

You can retrieve the path for the user's Documents folder like this:
DocFolder = Environ("HOMEDRIVE") & Environ("HOMEPATH") & "\Documents"

Related

VBA store path including Environ("username") in a text file

I am trying to create a text file that stores a folder path. This text file is then referenced via a vba sub. The path I want to use is something like:
"C:\Users\" & Environ("username") & "\AppData\Roaming\Microsoft\Templates"
This works fine in the sub but I've tried all kinds of variations in the text file but none of them get recognised and trigger error 52 - bad file.
Is there a way to make this work? I'm trying to allow people to set a different file path without needing to modify the code.
If you are trying to provide a path to the folder where user templates are stored then you could try
ActiveDocument.AttachedTemplate.Path
as an alternative (returns the path to the folder where the current template is stored for the user).
Otherwise store the path template as something like
"C:\Users\###UserName###\AppData\Roaming\Microsoft\Templates"
Which gives you a single string to retrieve. Then you can use the VBA Replace function to change the ###UserName### to the value of Environ("UserName)"
my_user_path = replace(my_path_template, Environ$("UserName"))
You might also want to explore using either a CustomDocumentProperty, or a Variables, to store your path template as this keeps the path template string as part of the Document or Template and not in a separate file.

Get name of file stored in SQL

I am modifying old application and I have to add functionality to allow user view a file from SQL. File needs to be saved in temporary folder and deleted after closing application. I've managed to do all above, but I have to get filename of downloaded file (now Im using a string variable filename = "TemporaryDoc").
How can I get a filename from a data that is stored in datagridview.Rows(0).Items(0) ?

Visual Basic.NET Saving Preferences in a .txt or .ini

I want to save my preferences for a program. I just want to know how to do it, since I cant get how to save this file at my documents, because every computer has a different name and username, but using the
My.User.Name
returns 'USERNAME-PC-USERNAME' which doesn't work.
For example, I want the program to create this text file 'CPreferences' at 'C:\Users\'username'\Documents'. And then when the program is re-opened it will automatically load this file into itself, the file will basically contain 2 lines:
Option1:<Value 1>
Option2:<Value 2>
The values will represent choices, ofcourse. So fundamentally, my question is:
1) How to save this file automatically at this user's documents WITHOUT showing a savefiledialog?
2) How to automatically load it if the file there exists?
Thanks,
VB.Net has built-in features for storing and retrieving the user's settings. Just use them. You won't have to worry about how the settings are stored or where the files are. It all just works.
Using something along the lines of string = "----------- " & CurrentTitle & " (" & Now.ToString() & ") User " & Environment.UserName & " on computer " & Environment.UserDomainName & "------------"
will result in
----------- Google - Google Chrome (3/12/2012 2:09:49 AM) User Drise on computer Drise-LAPTOP ------------
Using a streamwriter with filename "C:\users\" & Environment.UserName & "..." should do the trick.
To auto-load the file, check if the file exists and use a streamreader with the same path variable as above, or if not, then set default settings.
For saving to the "My Documents" folder for the current user, this will return the directory path:
My.Computer.FileSystem.SpecialDirectories.MyDocuments
You can also use other items in "special directories" if you want things like the "downloads" or "my pictures" folders, or anything else like that.
I think what you're looking for is user configuration.
You can store settings for users that will be unique to the logged in user.
Use this as a reference for getting started with it:
http://www.codeproject.com/Articles/12252/Application-settings-in-VB-NET-2-0-and-Visual-Stud

Capture only the file path from the file upload control

I am trying to update some local access databases from a web database. When I am accessing the web page, I want the user to select a folder on the local hard drive where the DB's reside that will be updated by the program. I actually have been using the File Upload control to do this as it has allowed me to check the file extensions on the local DB's their file size and other misc. items.
This captures the full path with the file name...
fileName = FileUploadAccess.PostedFile.FileName.ToLower
Now I have a need to capture the full path of the db's on the local hard drive. I can get the full path with the filename, but then I need to write a bunch of code to strip the filename from the path variable.
Is there a simple way to capture the path of the location the DB when the file location is selected, something like this....
Dim thePath As String = System.IO.Path.GetFullPath
Thanks for any suggestions.
You can use IO.Path.GetDirectoryName
Here is a sample code:
Dim MyDirectoryPath As String = System.IO.Path.GetDirectoryName(MyFullPath)

VBA How to get path to The Current Users Application data folder?

In general,
Using VBA, how do I determine where the Current users Application Data folder is?
The FileSystemObjects special folders only knows about 3 folders
WindowsFolder
SystemFolder
TemporaryFolder
Specifically, I need a Word Macro to copy a file to the a folder under the Application Data folder.
e.g. In VB.Net I can use My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData to do this
You can use Environ("AppData") to get this path. Environ will pull any system variable, which can be found by using the set command at the DOS prompt.
Using advapi32.dll, you can get the USERPROFILE via
Environ("USERPROFILE")
Connect this with the "Application Data" directory (which has a standard, specific name) to get what you want
CStr(Environ("USERPROFILE") & "\Application Data")
For more information, check out MSDN