Modules & VBA :: Create Subfolder And Copy File - Path Is Variable
Apr 18, 2014
I have a folder which holds 1000s of pictures organised in subfolders, for example:
D:~AI Database Print Scans2009family and
D:~AI Database Print Scans2009holiday
And so forth. In total at the moment 17 main subfolders, each of which hold another 2-3 subfolders.
I am putting together a database to bring pictures together with all sorts of details. I import the picture via hyperlink and complete the various fields. All that works fine but there are a lot of pictures! And it gets confusing to see which ones have already been entered into the database and which ones haven’t.
One solution for this is to copy the pictures that have been “completed” to another folder. I have found a way to do that:
Dim fs As Object
Dim oldPath As String, newPath As String
oldPath = Forms!frmPrintDetails.txtPath1
newPath = "D:~AI Database Print ScansCompleted_Entries"
Set fs = CreateObject("Scripting.FileSystemObject")
fs.CopyFile oldPath, newPath
Set fs = Nothing
Works fine, but the problem is that I loose the subfolder structure, it copies all pictures to the same main folder. I’d like to maintain the subfolder structure and add code to create the correct subfolders and next copy the picture. With the different paths I’m lost. I don’t know how to extract the correct path in code. I’d also like to either rename or remove the picture once I have completed entry of the details. The problem I have again is that I don’t know how to code for a changing path.
I am still trying to copy an Excel file from a parent folder to a sub-folder, that this code creates, and name the copied file with the name used to name the sub-folder, using the name entered in a control field (named 'TheDirName) of an Access 2007 form. Here is my VBA, which names the copied file "TheDirName.xlsx.:
Private Sub MakeDir_Click() Dim appExcel As Excel.Application Dim lngLastDataRow As Long Dim Folder_Path As String 'Create path for customer folder & files
I'm having another one of those days but I'm getting a file path and file name from a dialogbox and forgotten when the VBA property is to return the full file path and file name.
This code works fine for return the filename only:
Code:
Private Sub TEST() Dim f As Object Set f = Application.FileDialog(3) f.AllowMultiSelect = True If f.Show Then For I = 1 To f.SelectedItems.Count MsgBox Filename(f.SelectedItems(I)) Next End If End Sub
Instead of using 'Filename' what else can I use to return what I need?
Im trying to programmatically (without any user intervention) retrieve the long path name for a given file. It seems to me this should be a rather easy thing to achieve using Access VBA. Ive tried using various FileSystemObject methods with no luck. Ive Googled many variants of VBA get full path without any meaningful hits. provide the first string as a parameter to some object and have it magically return the second string.
I've recently created a new Access 2010 Database which I'm developing an interface for in VBA. I've created a new Userform in the Visual Studio (this required me to add the Userform button). I'm finding that when I insert the Multipage object which I need to use on the form I can no longer run the Userform. When I attempt to run, I get the error 'Path/File Access Error' followed by 'Run time error 75 - Could not find the specified object'.
It's definitely linked to the Multipage which I've inserted from the toolbox (standard object) as the form runs fine when it is not there and with other objects (have tested all other toolbox items). There is currently no code in written in the project, no tables or queries set up in the database therefore nothing is running when the form loads.
I've successfully used Multipages in a number of other VBA interfaces both in Access and Excel so not sure why they are causing a problem here. I've also just created a userform in exactly the same way in a new Excel sheet and it runs fine with the multipage.
I am using MS Access 2010. I have a code that I am using that loops through a folder gather all the names of the files in the folder and inserts them into a table (shown below). The table is named "tblFiles" there are two columns in the table titled file name and file path. What I want to do is to also loop through the same folder to find the file path of the files and insert them into the file path column has a hyperlink where users can just click on the hyperlink and the file opens.
Private Sub Form_Load() Dim fs, f, f1, fc, s Dim rs As DAO.Recordset Set rs = CurrentDb.OpenRecordset("tblFiles")
I have the code below and I want it to open a file from my documents folder. The only problem is that every computers path is different to this folder. Any easy way to work around and open a file in My Documents without the full path?
I want to eliminate the part of the path in red and make it universal because computers will have a different number.
Operating System: Windows 7
Code below:
Public Function AddITARPicOffloadAnalysis() Dim xlApp As Object Set xlApp = CreateObject("Excel.Application") With xlApp Dim wb As Object Dim ws As Object Dim Lastrow As Long
In the access form I want to add a button with a special functionality.
After clicking "Select file" button special window should be open (or something else). It should give user a possibility of files locating (doc, pdf, rtf, txt ...).
After selecting the file and confirm the choice in the table "File_location" in database path to the file should be saved .
I currently have a working model which opens up a word document template, fills the bookmarks with info from access, saves the file as a preset name and then send the document on Outlook.
What I would like to do is save the document as a variable, preferably as something like " Climbing Request for site (and then to lift the site name from Access form field and insert here) "
E.G " Climbing Request - Newcastle Central Station.doc"
I might be able to get "super easy mail merge" to work, but the problem is i want clicking the "merge" button to launch a file chooser box- so i can navigate to the word doc i want to use for the merge (destination doc will change with the currently selected record- i'm not merging a single record, however).
Basically i want to do exactly what right clicking on a table/query, then choosing "export" then choosing "merge with word" does (access 2007).
Can't do as a report because we may have "complex" letters- with graphics and/or tables.
why is something that is a simple right-click menu option so difficult to automate??
When I execute the below function I get an error. If I use the commented out "Open" line it works fine. I get Run-time error '52'. Bad file name or number.
Private Sub GenerateSSA_Click() Dim strRA As Variant, strFileNew As String, strFileBlank As String Dim intFileOut As Integer Dim rstWork As DAO.Recordset Dim dbs As DAO.Database Dim qdf As DAO.QueryDef
i'm using a form with an unbound text box to temporarily hold data that i want to use in several other places (all those functions work great). last step is to save the newly created table with a different name (will be used for a mail merge later so must be a separate table or else we'd have to filter thousands of records during each mail merge) and i want to use the data i've temporarily held in my unbound text box within my form as the name in the save as function.
can i specify a variable as a file name within the save as function? is there a better way?
I'm having problems creating a second subfolder in the main folder.
The main folder is used to keep inside the reviews of clients inside.
The code I have now, will only create a main folder if it does not exist and then a subfolder with the BIN nr, type review and date. If the client would have a diferent ones and in diferent years. So if it has first "Prototype Model", the next one could be "Prototype Review". The part of the code that checks if the main folder exist works, but how to let the code create in the main folder the second review subfolder? Please see below code I managed so far:
Code: Private Sub btn_Create_Folder_Click() 'XXXXXXXXXX working onXXXXXXXXXXXXXX Dim path1 As String Dim path2 As String path1 = "C:Test_FolderMedium" & Me.BIN & "_" & RTrim(Me.LE_Name) & "" path2 = "C:Test_FolderHigh" & Me.BIN & "_" & RTrim(Me.LE_Name) & ""
I have a tree-view object that is filled with a specific folder list, when a command button is pressed I would like too expand to a specific node based on a variable/foldername.
How to achieve this? My knowledge of tree-view is limited and I am still learning VBA.
Set up a txtbox that will house a variable (no worries)
I want a button that when clicked to open a "MS Windows window" that allows the user to navigate to a folder. When done I need that path to be placed in the textbox I set up (Or to a variable)
Does that make sense?
I thank you all for your help it is very appreciated.
I am trying to set up something to be able to take me to a folder that holds various forms for personnel. I have a query that generates the link for each person. I have tried to set it up as a hyperlink in ACCESS 2013 and it displays as one but doesn't act like one.
I want to be able to click the link and have it open up a personnel folder for that individual. I can't find a MACRO that I can create to do it. Example of my query is that it creates a link K:Main BreakdownSection BreakdownPersonnel FoldersName and the name is the variable part.
My next problem will be to have it create that folder when we have new personnel arriving.
I would also note that I have not worked with ACCESS in many years and much of what I was able to do with 2002 and 2003 doesn't work with the newer versions of ACCESS.
All I need to do is copy an excel file from a location (while coping the file, the location of the source file remains same all the time)and paste that excel file where ever I want (Browser Option) from an Access VBA.
Is it possible in access, to create a button that will copy a file to a new directory? Specifically, the data field in question is an access hyperlink that we can click on to open a PDF drawing of a part. I just want to copy the file the hyperlink points to, into a new directory.
I've got the forms and queries in one .accdb file and my tables in a separate .accdb file. The forms file links to the tables in the tables file. The tables file resides in a folder called simply enough C:acc_tables and thats where i browsed to (obviously) when i set up the linkage.
One of the users does not wish (for whatever goddamn reason) to create a C:acc_tables file to stick the tables file in , and wants the tables file in some other folder.. Unfortunately this user does not have the skills to delete the existing links and re-link to the tables file after putting it in the folder he wants.
Where in the file that holds the forms and and queries do i find the path setting to the tables linked file? Can it be changed without deleting links and then re-linking?
I need some simple code that will copy an Excel file or a table in Access to a specific location on an FTP server. I would think this would be a very simple task, but I have yet to find any sample code that is *simple*. I have seen lots of code that requires downloading this dll or that mda, but the examples don't work. There must be something built into MS Access 2010 that will allow a file to be uploaded to an FTP site.
All the variables are known:
The FTP location (it never changes) The FTP Username and Password (they never change) The destination folder on the FTP site (it never changes) The File type (it never changes) The File name (available from the form in Access from which this will be executed)
I can either produce an output file, then copy it to the FTP site, or I can export the table directly to the FTP site with the file name for that day.
This seems to be a very simple task with no simple solution. Currently I am using an FTP app to get the file to the FTP site, but I would like to automate this. The process that creates the output file is already automated, so I would just like to add this to the existing code as its own module.
just made all that above up and none of it is a real function/command in VBA, but is just the kind of thing I'm looking for.
I would think that since I can download and XML file from an FTP site that it should be child's play to upload a simple file to an FTP site, but I can't figure it out.
I have used Transfer text cmd to export query to text in MS access. This works fine. path= "D:/test/"DoCmd.TransferText acExportFixed,"Query1",path,False But i need to change the path dyanmically as my wish when i run this query. Like i may save my txt in desktop or C: or D:. I dont want to hard code path as above.
Is there any way to achieve this? If i get the dyanmic location stored in path variable i can achieve it. But i dont know how to achieve this.
Actually i was confused Docmd.OutputTo acOutputQuery,query1
Above query prompts me for selecting location. But transferText doesn't? why?
As this application is stored on server. If i give a static path, its exporting in Server D:/test/ But i need this to be stored in my local. This can be done only if it prompts box for user to select the location.
I would like to read a TIFfle to ACCESS, and store its content as hexadecimal like below to further other process..., how can I achieve this change and storage??