We have a set of users who have an outlook template (with same name) stored in their machines.
I want to create a hyperlink clicking on which will open that .oft file from their machine and they can use it further. Basically I need to know whether by using any script, we can get the location/machine name or not.
Is that possible?
Environment variables provide this type of information.
http://www.slipstick.com/developer/windows-environment-variables-outlook-macros/
Sub EnumSEVars()
Dim strVar As String
Dim i As Long
For i = 1 To 255
strVar = Environ$(i)
If LenB(strVar) = 0& Then Exit For
Debug.Print strVar
Next
End Sub
http://www.askvg.com/list-of-environment-variables-in-windows-xp-vista-and-7/
http://ss64.com/nt/syntax-variables.html
Related
Scenario:
From an Access-form with selected recordset, a report is filled with data, this is converted via VBA into HTML format and sent with Outlook. The content then appears as HTML in the email-body of the recipient. This contains a link that points to the recordset in this form. So assuming the recipient also has ACCESS and also the exact same database (and same location & content), the link would open his database file when clicked, then open the form, then open that exact record by using the query.
Based on this...
...I added a text field into my report with this content and marked it as a hyperlink:
Click here#C:\MainDatabase.accdb#Query frmForm01
Click the hyperlink in the report works (opens Access & file), the link in the locally stored HTML-tempfile also works.
Problem:
Although the link is sent, also appears in the recipient email-body as link "Click here", but displayed link is not clickable, just blue underlined text!
After a lot of experimenting I found out that it's all Outlook! The link is intact in the Outlook-mail-body preview before sending....it must be an Outlook-setting that converts the link into text during/for sending. In the Outlook menu I have already checked the format settings: convert to HTML is OK!(not plain text). So what else could be the cause??
Would be very grateful for solutions. Thanks!
My code:
Sub CreateHTMLMail()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim FSO As Object
Dim AttchFile As String, EmailTo As String, strSig As String
Set OutApp = New Outlook.Application
Set OutMail = OutApp.CreateItem(olMailItem)
AttchFile = "C:\AttachmTemp.htm"
EmailTo = "abcd#efgh.com"
DoCmd.OpenReport "NewReport", acViewReport, , "[ID]='" & Me.ID & "'", acHidden
DoCmd.OutputTo acOutputReport, "NewReport", acFormatHTML, AttchFile
Set FSO = CreateObject("Scripting.FileSystemObject")
strSig = FSO.OpenTextFile(AttchFile).ReadAll
With OutMail
.TO = EmailTo
.Subject = "New Message"
.BodyFormat = olFormatHTML
.HTMLBody = strSig
.send
End With
End If
Kill AttchFile
Set OutApp = Nothing
Set OutMail = Nothing
End Sub
I do this using a custom URL protocol handler.
First, create (and distribute after testing) a .reg file like this (replace myapp by your application name):
Windows Registry Editor Version 5.00
; Andre, 2019
[HKEY_CLASSES_ROOT\myapp]
#="URL:myapp-Open"
"URL Protocol"=""
"EditFlags"=hex:02,00,00,00
[HKEY_CLASSES_ROOT\myapp\DefaultIcon]
#="C:\\path\\myapp\\myapp.ico"
[HKEY_CLASSES_ROOT\myapp\shell]
#="open"
[HKEY_CLASSES_ROOT\myapp\shell\open]
[HKEY_CLASSES_ROOT\myapp\shell\open\command]
; using a .vbs to start my app
; #="wscript C:\\path\\myapp\\Startmyapp.vbs \"%1\""
; (untested) starting Access directly, needs the /cmd switch
#="\"C:\\Program Files (x86)\\Microsoft Office\\Office16\\msaccess.exe\" C:\\path\\myapp\\Myapp.accde /cmd \"%1\""
; If you use Outlook, prevent the Security warning
; https://stackoverflow.com/a/34660198/3820271
; Note: the whole subtree starting with (at least) "Security" will be created.
; This path is for Office 2016.
[HKEY_CURRENT_USER\Software\Policies\Microsoft\Office\16.0\Common\Security\Trusted Protocols\All Applications\myapp:]
Note that I use a .vbs script to start my Access application, it should work as well with the path to msaccess.exe plus your local frontend.
See comments in myapp\shell\open\command
Then in your HTML email, use URLs like this:
url:myapp:ID:2357
ID:2357 will be passed as command-line parameter to your application.
See Opening Microsoft Access with parameters on how to read this string, then parse it in your Autoexec function and open your form.
To test this, simply type myapp:ID:2357 in Start/Run or in a Cmd window.
I have a form in Microsoft Access which lets users upload attachments to each record. I'd like to make it a little user friendly by letting users drag and drop files into the attachment field. What is the best way of doing this/how do I do this?
Drag and drop might be a bit more sophisticated, how about VBA code to manipulate what you wish to achieve? This article has a great reference to what you wish to do. http://www.access-freak.com/tutorials.html#Tutorial07
Here is a way to drag and drop "attached" files for use with MS Access database.
(Currently using Office 365 Version 1811)
MS Access currently allows drag and drop to a hyperlink field.
Using this capability this example allows drag and drop to store an attachment file to a storage location while keeping a link to the original and new locations. The event runs when a file is dropped into the HyperlinkIn box on the form or when the hyperlink is changed the normal way.
It is better to store the file in a storage location with a link than to store it within the .accdb file due to the 2GB limitation. You might call this a database + file server architecture. By using the record number and optionally the database and table name and attachment number you can ensure unique file names.
Make a Table and Form with 3 fields.
ID (AutoNumber)
HyperlInkIN (hyperlink)
HyperLinkOUT (hyperlink)
Insert this VBS code for AfterUpdate event for the HyperlinkIn form control.
Private Sub HyperlinkIN_AfterUpdate()
Dim InPath As String
Dim FileName As String
Dim OutFolder As String
Dim OutPath As String
Dim RecordNo As String
Dim FileExt As String
OutFolder = "\\networkdrive\vol1\attachments\" 'specify the output folder
InPath = Me!HyperlinkIN.Hyperlink.Address
RecordNo = Me!ID
If Len(InPath) > 0 Then
FileName = Right(InPath, Len(InPath) - InStrRev(InPath, "\")) 'get the file name
FileExt = Right(FileName, Len(FileName) - InStrRev(FileName, ".") + 1) ' get the file extension with dot
'build the new path with output folder path and record number and date and extension
OutPath = OutFolder & "Record " & RecordNo & " Attachment " & Format(Now(), "ddmmmyy") & FileExt
FileCopy InPath, OutPath
Me!HyperlinkOUT = "#" & OutPath & "#"
MsgBox "Copied file to archives " & vbCrLf & InPath & vbCrLf & OutPath
End If
End Sub
I am somewhat inexperienced with vba so there may be some better ways to ensure and verify a successful file copy but this example works for me and is easy for me to understand. I used the MsgBox to help debug with the actual file copy commented out.
Because this page comes as first when searching for "MS Access drag drop", I'm adding my part here. If you are after some cool UI, you can checkout my Github for sample database using .NET wrapper dll. Which allows you to simply call a function and to open filedialog with file-drag-and-drop function. Result is returned as a JSONArray string.
code can be simple as
Dim FilePaths As String
FilePaths = gDll.DLL.ShowDialogForFile("No multiple files allowed", False)
'Will return a JSONArray string.
'Multiple files can be opend by setting AllowMulti:=true
here what it looks like;
I'm in the process of creating a web portal for bulk new user creation on both our AS400 and Domain, I've been able to get everything to work except for passing the variables from the HTML form to the batch files.
The batch files already existed and to keep this as simple as possible I decided to reuse them as this will be a strictly internal application.
I've declared my variables to be the input from the form and set them to be called by the vb script when running the batch file, however they are not being passed as the variables but as what is stated in the code.
Can someone tell me what I'm doing wrong as I've not been able to find much information from searching the web on this problem?
If you need more information please let me know and I'll provide it.
<script language="VBScript">
strCode = textbox0.Value
strName = textbox1.Value
strIPMG = textbox2.Value
strServer = textbox3.Value
Sub isetup
dim shell
set shell=createobject("wscript.shell")
shell.run "N:\wwwroot\users\iSETUP01.bat strCode strName strIPGM strServer"
set shell=nothing
End Sub
Sub wsetup()
dim shell
set shell=createobject("wscript.shell")
shell.run "N:\wwwroot\users\wSETUP.bat strCode strIPGM"
set shell=nothing
End Sub
</script>
Don't you need something like...
"N:\wwwroot\users\wSETUP.bat " & strCode & " " & strIPGM
I have a Icon of PDF in my form that I have created in Access 2010. There are 3 tabs in that form; each tab have a separate form page and PDF icon is common for all the tabs.
Now I want that whenever a user click on that icon a PDF file of that form get created.
I have written this code
Private Sub cmdPrintReportPDF_Click()
Dim strDefaultPrinter As String
strDefaultPrinter = Application.Printer.DeviceName
**Set Application.Printer = Application.Printers("PDFCreator")**
'DoCmd.PrintOut acPrintAll
DoCmd.OpenReport "Graph_report", acViewNormal
Set Application.Printer = Application.Printers(strDefaultPrinter)
End Sub
But I'm getting the following error:
Invalid procedure call or argument on line no 4.
Set Application.Printer = Application.Printers("PDFCreator")
I have PDFCreator installed and this line, which triggers an error for you, does not trigger an error for me.
Set Application.Printer = Application.Printers("PDFCreator")
Go to the Immediate Window of the VB Editor and see if you also get an error with this line:
? Application.Printers("PDFCreator").DeviceName
If that also triggers an error, you probably don't have a printer whose DeviceName is PDFCreator. You can list the names of the printers with this procedure.
Public Sub ListPrinters()
Dim objPrinter As Printer
For Each objPrinter In Application.Printers
Debug.Print objPrinter.DeviceName
Next objPrinter
End Sub
However, with Access 2010, I think you can create a PDF without using your PDFCreator print device. At least this works for me with Access 2007, so I'm guessing it will work for you.
Private Sub cmdSaveAsPdf3_Click()
Dim strPath AS String
strPath = CurrentProject.Path & Chr(92) & "Sample3.pdf"
DoCmd.OutputTo acOutputForm, "fsubSample3", acFormatPDF, strPath
End Sub
That button click code creates a PDF (Sample3.pdf) of the form (fsubSample3) embedded in a page of my main form's tab control ... which is what I thought you wanted based on the original version of your question. Now it seems you're wanting to create a PDF of a report rather than a form. You can adapt the DoCmd.OutputTo line to use a report instead of a form.
Change this:
Set Application.Printer = Application.Printers("PDFCreator")
...to this:
Application.Printer = Application.Printers("PDFCreator")
Application.Printer is a property, not an object, so it doesn't use SET to change it.
I have an access 2007 Database that outputs a report in excel format, the report is dependent on a date parameter that is chosen by the user. This parameter is selected via a textbox (text100) that has a pop up calendar. I would like to use the date in the text box(text100) as part of the filename. I am using the transferspreadsheet method to create the export, However I do not need the column headers. Once the file is created I have the code open the file and delete the headers. Also the current code is using todays date in the filename which is not accurate. The filename needs to reflect the date that was selected by the user in the text box from the pop up calendar
Ok here is the code.
Sub Branch298nohdr()
Dim Filename As String
Dim Path As String
Dim Branch As Integer
Dim Text100 As Date
Dim xl
Branch = "298"
Path = "Path" & Branch & "\"
Filename = "Identity Report " & Branch & " " & _
Replace(Text100, ":", " ") & ".xls"
If Dir(Path & Filename) <> "" Then
MsgBox "File has been created already"
If Dir(Path & Filename) <> "" Then
GoTo 53
End If
Else
Set xl = CreateObject("excel.application")
TempVars.Add "branchnum", Branch
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, _
"queryname", Path & Filename, False
xl.workbooks.Open Path & Filename
With xl
.Rows("1:1").entirerow.Delete
.Columns("L:L").select
.Selection.NumberFormat = "0"
.range("a1").select
xl.workbooks(1).Close Savechanges:=True
xl.Quit
Set xl = Nothing
53
MsgBox "Done!"
End With
TempVars.Remove "branchnum"
End If
Branch298nohdr_Exit:
Exit Sub
End Sub
Text 100 is where the user selects a date via a pop up calendar. I would like to use this date as part of the file name. Currently using the text100 as part of the filename it is being referenced as 12:00 am, and then adds this to the file name. I hope this clears up my intention.
Text 100 gets set on the opening form then there are several buttons which allow the user to pick between several branches or all branches.
Well the obvious question is, where does Text100 get first set?
Another style comment, it is better to do
goto ExitSub
'...
ExitSub:
Then your "GoTo 53" - its a little more meaningful.
At that rate, it would be better to move your "Done" message outside of the IF statements, and the TempVars doesn't seem to have a purpose; remove it.
Edit:
I presume if Text100 is a textbox on the form, then the line that reads:
Dim Text100 As Date
is going to override that reference in your code.
If you are referencing that textbox in your code, you need to do it this way:
foo = me.Text100
' or
foo = Forms!FormName.Text100
It's a little tough to determine exactly what your question is, but I think you are asking, "how do I use the contents of a text box as an export file name?" It sounds like somewhere in your code it creates a string for the filename that has & now() tagged on to the end to use the current date in the filename. Can you simply replace the '& now()' with '& textbox.value'?
A JD Long said it is hard to see any question in your posting. Maybe you should edit it again.
But as a general remark you need to escape any special characters that the user entered before you are going to use the input in a file name.
The following reserved characters are not allowed:
< > : " / \ | ? *
For more details on naming files in Windows see: Naming a File or Directory in MSDN.