Open folder with * instead of the whole folder name - ms-access

I want to open a folder by not using the whole foldername.
The Foldername is 219448_CustomerName
But I don´t know the CustomerName so I just want to use the number 219448 with * in the end.
Is this possible?
I´m using it like this, but it´s not working.
Call Shell("explorer.exe" & " " & "G:\Money\Credit Assessment\Customer\219448*", vbNormalFocus)
If I run it like this, the Explorer is just opening "MyDocuments".
I also want to add another folder behind the star to go deeper like:
Call Shell("explorer.exe" & " " & "G:\Money\Credit Assessment\Customer\219448*\Info", vbNormalFocus)

The shell does not support paths where wildcards represent directory names.
There can be multiple wildcard matches for such a path, so what would explorer.exe do with 50 different paths?
If you want to actually do this, you will need to manually locate a concrete path from the wildcard and pass that to explorer.
Example:
'wildcard must be in the last path-part, no trailing \
inputPath = "G:\Money\Credit Assessment\Customer\219448*"
'get fixed path
fixedPath = Left$(inputPath, InStrRev(inputPath, "\"))
'wildcard part
wildPath = Mid$(inputPath, InStrRev(inputPath, "\") + 1)
'//loop fixed path looking for a wildcard match on subdirs
aDir = Dir$(fixedPath & "*.*", vbDirectory)
Do While Len(aDir)
If aDir <> "." And aDir <> ".." And GetAttr(fixedPath & aDir) And vbDirectory Then
If aDir Like wildPath Then
MsgBox "found: " & fixedPath & aDir
End If
End If
aDir = Dir$()
Loop

Related

Open folder or create folder if doesn't exist with different constant parent folder can be on 3 different path

I have a code to create folder or open folder if exist which works completely fine.
Now my only problem is that there can be 3 users of this database and the 3 users has individual parent folder path. They all use and share all the folders in the parent folder and has the same parent folder name, only the path is different for the parent folder.
My existing code as follows:
Private Sub Command299_Click()
Const strParent = "C:\Users\xxx\xxx\Jobs\"
Dim strJobID As String
Dim strClient As String
Dim strFolder As String
Dim fso As Object
' Create FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
' Get year from control - modify as needed
strClient = "(" & Me.[Client ID] & ") " & [Client Name]
' Path with year
strFolder = strParent & strClient
' Check whether folder exists
If fso.FolderExists(strFolder) = False Then
' If not, create it
fso.CreateFolder strFolder
End If
' Get student ID from control
strJobID = Me.[Job ID] & " " & [Job name]
' Full path
strFolder = strFolder & "\" & strJobID
' Check whether folder exists
If fso.FolderExists(strFolder) = False Then
' If not, create it
fso.CreateFolder strFolder
End If
' Open it
Shell "explorer.exe " & strFolder, vbNormalFocus
End Sub
As I said it does work completely fine on my computer where the const parent folder path is what is in the code, but how can I make this code work for different path?
My 1st idea was to give an "or" statement in the Const line
Const strParent = "C:\Users\xxx\xxx\Jobs\"
But it didn't want to work. Is there any way to give 3 constant path for the parent folder and if one of them exists, work from there?
Thank you for any help!
Lots of options:
If you have a file server, move the files there and use \\servername\share
If you don't have a file server, have one user share the folder and on all 3 computers, connect to the shared drive using the same letter then use that path for access.
if neither of those appeal to you, create a users table in your database with two fields, username and path. Use the Environ("USERNAME") to get the username (as above) and put the path they need in another column. lookup with
Path = DLookup("fieldUserPath", "tblUsers", "fieldUsername = '" & Environ("USERNAME") & "'")

Save a query as text tab delimited but include ".ail2" in the saved name. (ACCESS)

I want to export a query as a text file from an access database but using vba. The issue is I need to save it with .ail2 in the name.
basically I want it of the form: "currentdate_version.ail2".txt (the quotations are very important otherwise it won't work).
So for example todays first version would look like:
"20182910_1.ail2".txt
I have tried exporting it manually and saving it as this but the export wizard doesn't seem to like the quotation marks in the saved name. I have therefore been exporting it (using a custom saved export that i've labelled test1 - it includes the headers of each column, sets the text qualifier as 'none', the field delimiter as 'tab' and file format is 'delimited').
I am using the following code in access, the first part just makes sure the folder with the current date exists.
Private Sub ExportExcel()
Dim myQueryName As String
Dim myExportFileName As String
Dim strSheets As String
Dim sFolderPath As String
Dim filename As Variant
Dim i As Integer
strSheets = Format(Date, "yyyymmdd")
sFolderPath = "M:\AIL2Files\" & strSheets & ""
Dim fdObj As Object
Set fdObj = CreateObject("Scripting.FileSystemObject")
If fdObj.FolderExists("" & sFolderPath & "") Then
Else
fdObj.CreateFolder ("" & sFolderPath & "")
End If
i = 1
filename = Dir(sFolderPath & "\*" & i & ".txt")
Do While Len(filename) > 0
filename = Dir(sFolderPath & "\*" & i & ".txt")
i = i + 1
Loop
myQueryName = "001_querytest"
myExportFileName = "" & sFolderPath & "\" & Chr(34) & "" & strSheets & "_" & i & ".ail2" & Chr(34) & ".txt"
DoCmd.TransferText acExportDelim, "test1", myQueryName, myExportFileName, True
End Sub
test1 isn't being picked up even though its a 'saved export'. I assume I'm doing this part wrong... but even still I reckon the save won't be successful and will not include the quotation marks.
Thanks.
EDIT:
I have tried doing the following instead:
DoCmd.TransferText transferType:=acExportDelim, TableName:=myQueryName, filename:=myExportFileName, hasfieldnames:=True
It now saves, but again not including the quotation marks as desired. Whats interesting is when I type ?myExportFileName in the immediate window, it displays my desired filename but the command is clearly not working correctly as I get it of the form:
_20181029_1#ail2_
Instead...
Here is image if I use save as:
I end up getting:
There are some misconceptions here.
Windows file names cannot contain double quotes ", period. And you don't need them, either. Just save your file as filename.ail2.
This is what you get when doing "Save as". Tell Explorer to show file extensions, and you'll see that you don't have "filename.ail2".txt but filename.ail2.
You only need
myExportFileName = sFolderPath & "\" & strSheets & "_" & i & ".ail2"
test1 isn't being picked up even though its a 'saved export'.
DoCmd.TransferText doesn't use saved exports, but export specifications. See here for the difference:
Can I programmatically get at all Import/Export Specs in MS Access 2010?
Addendum
DoCmd.TransferText could throw a runtime error when given an illegal file name, but apparently it tries to save the day by exchanging the illegal characters by _, hence _20181029_1#ail2_ (.txt)
A workaround to this is first saving the file as a .txt using DoCmd.TransferText, but running a shell and renaming. Like such:
myExportFileName = sFolderPath & "\" & strSheets & "_" & i & ".txt"
DoCmd.TransferText TransferType:=acExportDelim, SpecificationName:="034_AILFILE Export Specification", TableName:=myQueryName, filename:=myExportFileName, HasFieldnames:=True
Set wshShell = CreateObject("Wscript.Shell")
strDocuments = wshShell.SpecialFolders("M:\AIL2Files\" & strSheets & "")
oldFileName = myExportFileName
newFileName = sFolderPath & "\" & strSheets & "_" & i & ".ail2"
Name oldFileName As newFileName
There is undoubtedly cleaner ways of doing this but I imagine that this method could be used to save any files that have non traditional extensions, but fundamentally follow the format of a .txt file.

"Expected End of Statement" when concatenating string

I am attempting to embed an PDF iframe viewer into a web based form I am building.
I have done this multiple times but for the life of me I can not get it right this time.
''This attaches a PDF uploaded on a previous form and should display it within
''an iFrame.
If "aObjects("RD20_AttachRandR")" <> "avar1" Then
fcLabel = "<iframe src=""" & "aObjects("RD20_AttachRandR ")" & ".PDF" & _
" width=800px height=1000px ><p>Your browser does not support iframes.</p></iframe>"
End If
Somewhere in the line starting with fcLabel I am missing an " that ends the string that I am passing through. But I am unable to find it.
Presumably aObjects is a dictionary (or other collection) variable, so you need to remove the outer double quotes. Also, the second time you use that variable the item name string has a trailing space ("RD20_AttachRandR ") which you may want to remove.
If aObjects("RD20_AttachRandR") <> "avar1" Then
fcLabel = "<iframe src=""" & aObjects("RD20_AttachRandR") & ".PDF" & _
" width=800px height=1000px ><p>Your browser does not support iframes.</p></iframe>"
End If
As noted by Ansgar Wiechers,
I had forgotten to remove a trailing space at the end of the aObject name.
I removed it and it works now.
Ta.

Making Directories and sub-directories - VBA

I'm writing a script in Access 2013 for work, I'm kinda of a neat freak with computers so I want to be able to output the data to a organized archive so over the years it will be, well, organized.
I know how to create a simple directory, but I want to create directories within directories.
This is my variable I have written for the path
strOutPath = CurrentProject.Path & "\MeijingOutput\" & MonthName(Month(Date)) & _
"_" & DatePart("YYYY", Date) & "\" & DatePart("m", Date) & "." & DatePart("d", Date) & "." & DatePart("yyyy", Date) & "\"
this comes out to be C:\Users\[user]\Documents\MeijingOutput\June_2015\6.24.2015\
Before, I was just outputting them all to the same folder "MeijingOutPut", and it worked since I was just making a new top level directory.
Is there a way I can get this code to work without having to manually check for each sub directory?
If Len(Dir(strOutPath, vbDirectory)) = 0 Then ' make the folder if it doesnt exist
MkDir strOutPath
End If
I have finally solved it, I did in fact have to manually check each directory. I used a loop and array though to make it seem simple
strOutPut(0) = CurrentProject.Path & "\MeijingOutput\"
strOutPut(1) = strOutPut(0) & MonthName(Month(Date)) & "_" & DatePart("YYYY", Date) & "\"
strOutPut(2) = strOutPut(1) & DatePart("m", Date) & "." & DatePart("d", Date) & "." & DatePart("yyyy", Date)
strOutPath = strOutPut(2)
And the main attraction
For i = 0 To 2
If Len(Dir(strOutPut(i), vbDirectory)) = 0 Then ' make the folder if it doesnt exist
MkDir strOutPut(i)
End If
Next i

Search Files with windows explorer

i have a list of many organizations, each org. has lists of hundreds of people, each person has a scan'd document in that organizations folder, now i have a btn on my app that opens the org folder, and the user is searching for that person, but the user wants the btn to open windows explorer automatically searching a person.
i found this code:
Shell("c:\Windows\explorer.exe ""search-ms:displayname=Search%20Results&crumb=System.Generic.String%3A" & <variable> & "&crumb=location:<your search location>%", vbNormalFocus)
but windows raises the folowing error:
Windows Cant find ". Check if spaled correctly...
any suggestions ?
I'm Adding here my code:
Private Sub cmdView_Click()
Dim strPath As String
strPath = CurrentProject.Path & "\Scans\" & DLookup("OrgName", "tblOrganizations", "ID=" & Me.OrgID)
'Shell "C:\WINDOWS\explorer.exe """ & strPath & "", vbNormalFocus
Call Shell("c:\Windows\explorer.exe ""search-ms:displayname=Search%20Results&crumb=System.Generic.String%3A" & Me.Phone & "&crumb=location:" & strPath & "%""", vbNormalFocus)
End Sub
Here is a simple solution, using only a common batch (.bat) file, which anyone can make using only notepad.exe:
:: Text to search for
SET name=Winamp
:: Directory to search in
SET dir=C:\Program Files (x86)
:: ** Command Line **
C:\Windows\Explorer.exe "search-ms:displayname=Search Results in %dir%&crumb=System.Generic.String:%name%&crumb=location:%dir%"
Notes -
The text to search for can be the full name, or just part of the name, of the file or directory to be searched for.
The search is NOT case sensitive, but will match a mixture of uppercase and lowercase.
The function will search the specified directory and all subdirectories of it.
Shell("c:\Windows\explorer.exe ""search-ms:displayname=Search%20Results&crumb=System.Generic.String%3A" & <variable> & "&crumb=location:<your search location>%""", vbNormalFocus)
This should fix it, as parakmiakos said, you missed a double (triple due to being a string) quote.
string folder = Uri.EscapeDataString(#"C:\");
string file = "size:huge";
string uri = "search:query=" + file + "&crumb=location:" + folder;
var files = Process.Start(new ProcessStartInfo(uri));