Guys,
Thanks for taking an interest in my problem. Please be patient with my ideas as I am not a professional developer. I am a Manufacturing Engineer that gets involved with application development when our IT guys either Can't, Don't or Won't complete our projects when we need them to.
It is Tuesday morning 7:30 am and I am back in the office.
You had asked about the "link". Here is my code that creates the email from Access VBA and creates the "link":
Code:
Private Sub cmdCreateEmail_Click()
Open "C:\Temp\OOSN.txt" For Output As #1
Print #1, Forms!frmMain.ToolNumber
Close #1
Let MyDBShortcut$ = "\\dbd03\nccode\Router_Proc\OOSN.bat"
'Format and display email below...
Set ol = CreateObject("Outlook.application")
Set NewMessage = ol.CreateItem(olMailItem)
With NewMessage
'Read in email addresses below...
Dim dbsMYDB As Database
Dim rstMYDIRList As DAO.Recordset
Set dbsMYDB = CurrentDb
Set rstMYDIRList = dbsMYDB.OpenRecordset("tblEmailList")
With rstMYDIRList
.MoveFirst
While Not rstMYDIRList.EOF
With NewMessage
.Recipients.Add rstMYDIRList!EmailAddress
End With
.MoveNext
Wend
End With
DoCmd.Hourglass 0
rstMYDIRList.Close
dbsMYDB.Close
'Read in email addresses above...
.Attachments.Add "C:\Temp\OOSN.txt"
.Subject = "Urgent Out-of-Service Notice! There is a tool that needs to be taken Out-of-Service..."
'Insert body and Hyperlink below...
.Body = "Please save the attachment(s) to C:\Temp and then click on the link below." & vbCrLf & vbCrLf & _
"<file:" & MyDBShortcut$ & ">" & vbCrLf & vbCrLf & _
"Thank you."
.Importance = 2 'This is a High Priority
.Display
End With
End Sub
This code is run from a command button on my Access form. When a user of the database enters data into my form, he will click this button and format an email that gets sent to several recipients for their review.
My ultimate goal is to provide a link to a piece of software (database, VB or something else) on the network that will determine the user's path to msaccess.exe and then create a batch file that opens the real database and automatically navigates to the correct record.
Here is another attempt at describing the entire process so that you may understand...
A user enters a record into my database. Let's say it is record 500 out of 1000 records. The tool number that this user is entering information about is tool number "1234". After entering some general data about this tool, the user presses the "Create Email" button. The code about creates a email message and the user presses the send button in Outlook.
Next, one of the recipients recieves the email. When he opens the email, there is a link inside. When he clicks on the link, the link will open up a piece of software on the network. The only purpose in this software that opens up is to get the path to the user's msaccess.exe and then create a batch file that will open up my database on the network using the full path like:
"C:\Program Files\Microsoft Office\Office11\Msaccess.exe" "C:\Temp\TestDB.mdb" /cmd "Hello World"
After creating the batch file, the software will call and execute the batch file which will ultimately open my database and automatically navigate to the correct record in the database.
When my database opens it will use this code to navigate to the correct record...
Code:
'This code looks for a text file that contains the part number to search
'for when the form opens up. If the text file cannot be found, then the
'form opens up and displays the first record.
Dim rs As Object
If Len(Dir("C:\Temp\OOSN.txt")) > 0 Then
Open "C:\Temp\OOSN.txt" For Input As #1
While Not EOF(1)
Line Input #1, Search$
Wend
Close #1
Kill "C:\Temp\OOSN.txt"
If Search$ <> "" Then
'Now find the record that matches Search$
'Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ToolNumber] = '" & Search$ & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End If
End If
'This code gets any command line arguments that may exist
Let Search$ = Command
If Search$ <> "" Then
'Now find the record that matches Search$
Set rs = Me.Recordset.Clone
rs.FindFirst "[ToolNumber] = '" & Search$ & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End If
By using the full path to Access, I have figured out that I can use command line parameters to gain access to data. The data will be used for navigating to the correct record in the database. In the example above, the data is "Hello World". If "Hello World" was a tool number, then I could just check the command line parameter to see if it is <> "", then navigate to the record named "Hello World".
Because there could be users that have a different version of Access or have Access stored in some other directory structure, I need a way to format a dynamic batch file that will always know the correct path to msaccess.exe from any user's computer.
If I can get this to work (and I will today), I can get rid of the need to have the user save the text file attachment in the email to their C:\Temp folder and start using the more automated approach using command line parameters. If you need to know more about command line arguments, look up "command" in VBA help.
I am tired of typing now. Does this help explain what I want to do? And if it does, are there any ideas how could accomplish this any easier.
Thanks,
David