If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Add email VBA to existing code
Hello, I am running this code in my WelcomeForm On Open event and when a
person is denyed access to the database and before OR after the database closes I would like a outlook email window to come up so they can email me. what and where would I add the code to the code below? Thanks! Private Sub Form_Open(Cancel As Integer) Dim db As DAO.Database Dim rst As DAO.Recordset Dim rstV As Recordset Dim stDocName As String Dim stLinkCriteria As String Set db = CurrentDb() Set rst = db.OpenRecordset("tbl_LoginID", dbOpenDynaset) If Not IsNull(Me.Text_Network_User) Then rst.FindFirst "strEmployeeUserID = '" & Me.Text_Network_User & "'" & " And strEmployeeUserID = '" & Me.Text_Network_User & "'" If rst.NoMatch Then MsgBox "You do not have access to this database!!! " & Chr(13) & _ "Please contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied" DoCmd.Quit Else stDocName = "WelcomeForm" DoCmd.OpenForm stDocName, , , stLinkCriteria End If End If End Sub -- Newbies need extra loven......... |
#2
|
|||
|
|||
Add email VBA to existing code
How about before docmd quit
-- Chris "Chad" wrote: Hello, I am running this code in my WelcomeForm On Open event and when a person is denyed access to the database and before OR after the database closes I would like a outlook email window to come up so they can email me. what and where would I add the code to the code below? Thanks! Private Sub Form_Open(Cancel As Integer) Dim db As DAO.Database Dim rst As DAO.Recordset Dim rstV As Recordset Dim stDocName As String Dim stLinkCriteria As String Set db = CurrentDb() Set rst = db.OpenRecordset("tbl_LoginID", dbOpenDynaset) If Not IsNull(Me.Text_Network_User) Then rst.FindFirst "strEmployeeUserID = '" & Me.Text_Network_User & "'" & " And strEmployeeUserID = '" & Me.Text_Network_User & "'" If rst.NoMatch Then MsgBox "You do not have access to this database!!! " & Chr(13) & _ "Please contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied" DoCmd.Quit Else stDocName = "WelcomeForm" DoCmd.OpenForm stDocName, , , stLinkCriteria End If End If End Sub -- Newbies need extra loven......... |
#3
|
|||
|
|||
Add email VBA to existing code
"Chad" wrote in message ... Hello, I am running this code in my WelcomeForm On Open event and when a person is denyed access to the database and before OR after the database closes I would like a outlook email window to come up so they can email me. what and where would I add the code to the code below? Thanks! Private Sub Form_Open(Cancel As Integer) Dim db As DAO.Database Dim rst As DAO.Recordset Dim rstV As Recordset Dim stDocName As String Dim stLinkCriteria As String ' add this Dim strTo As String Dim strSubject As String Dim strMessage As String Set db = CurrentDb() Set rst = db.OpenRecordset("tbl_LoginID", dbOpenDynaset) If Not IsNull(Me.Text_Network_User) Then rst.FindFirst "strEmployeeUserID = '" & Me.Text_Network_User & "'" & " And strEmployeeUserID = '" & Me.Text_Network_User & "'" If rst.NoMatch Then MsgBox "You do not have access to this database!!! " & Chr(13) & _ "Please contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied" 'add the code he strTo= " strSubject = "The subject you want" str Message = "The body of the message" DoCmd.SendObject acSendNoObject, , , strTo, , , strSubject, strMessage DoCmd.Quit Else stDocName = "WelcomeForm" DoCmd.OpenForm stDocName, , , stLinkCriteria End If End If End Sub -- Newbies need extra loven......... |
#4
|
|||
|
|||
Add email VBA to existing code
Thanks for the reply! I get a compile error Variable not Defined and it
highlights strTo. Here is the complete code im using if that helps. Maybe I put it in the wrong place..Thanks! Dim db As DAO.Database Dim rst As DAO.Recordset Dim rstV As Recordset Dim stDocName As String Dim stLinkCriteria As String Set db = CurrentDb() Set rst = db.OpenRecordset("tbl_LoginID", dbOpenDynaset) If Not IsNull(Me.Text_Network_User) Then rst.FindFirst "strEmployeeUserID = '" & Me.Text_Network_User & "'" & " And strEmployeeUserID = '" & Me.Text_Network_User & "'" If rst.NoMatch Then MsgBox "You do not have access to this database!!! " & Chr(13) & _ "Please contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied" strTo = " strSubject = "Cant open database" Str Message = "The body of the message" DoCmd.SendObject acSendNoObject, , , strTo, , , strSubject, strMessage DoCmd.Quit Else stDocName = "WelcomeForm" DoCmd.OpenForm stDocName, , , stLinkCriteria End If End If End Sub -- Newbies need extra loven......... "Arvin Meyer [MVP]" wrote: "Chad" wrote in message ... Hello, I am running this code in my WelcomeForm On Open event and when a person is denyed access to the database and before OR after the database closes I would like a outlook email window to come up so they can email me. what and where would I add the code to the code below? Thanks! Private Sub Form_Open(Cancel As Integer) Dim db As DAO.Database Dim rst As DAO.Recordset Dim rstV As Recordset Dim stDocName As String Dim stLinkCriteria As String ' add this Dim strTo As String Dim strSubject As String Dim strMessage As String Set db = CurrentDb() Set rst = db.OpenRecordset("tbl_LoginID", dbOpenDynaset) If Not IsNull(Me.Text_Network_User) Then rst.FindFirst "strEmployeeUserID = '" & Me.Text_Network_User & "'" & " And strEmployeeUserID = '" & Me.Text_Network_User & "'" If rst.NoMatch Then MsgBox "You do not have access to this database!!! " & Chr(13) & _ "Please contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied" 'add the code he strTo= " strSubject = "The subject you want" str Message = "The body of the message" DoCmd.SendObject acSendNoObject, , , strTo, , , strSubject, strMessage DoCmd.Quit Else stDocName = "WelcomeForm" DoCmd.OpenForm stDocName, , , stLinkCriteria End If End If End Sub -- Newbies need extra loven......... |
#5
|
|||
|
|||
Add email VBA to existing code
It looks as though you missed Arvin's instruction
' add this Dim strTo As String Dim strSubject As String Dim strMessage As String -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Chad" wrote in message ... Thanks for the reply! I get a compile error Variable not Defined and it highlights strTo. Here is the complete code im using if that helps. Maybe I put it in the wrong place..Thanks! Dim db As DAO.Database Dim rst As DAO.Recordset Dim rstV As Recordset Dim stDocName As String Dim stLinkCriteria As String Set db = CurrentDb() Set rst = db.OpenRecordset("tbl_LoginID", dbOpenDynaset) If Not IsNull(Me.Text_Network_User) Then rst.FindFirst "strEmployeeUserID = '" & Me.Text_Network_User & "'" & " And strEmployeeUserID = '" & Me.Text_Network_User & "'" If rst.NoMatch Then MsgBox "You do not have access to this database!!! " & Chr(13) & _ "Please contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied" strTo = " strSubject = "Cant open database" Str Message = "The body of the message" DoCmd.SendObject acSendNoObject, , , strTo, , , strSubject, strMessage DoCmd.Quit Else stDocName = "WelcomeForm" DoCmd.OpenForm stDocName, , , stLinkCriteria End If End If End Sub -- Newbies need extra loven......... "Arvin Meyer [MVP]" wrote: "Chad" wrote in message ... Hello, I am running this code in my WelcomeForm On Open event and when a person is denyed access to the database and before OR after the database closes I would like a outlook email window to come up so they can email me. what and where would I add the code to the code below? Thanks! Private Sub Form_Open(Cancel As Integer) Dim db As DAO.Database Dim rst As DAO.Recordset Dim rstV As Recordset Dim stDocName As String Dim stLinkCriteria As String ' add this Dim strTo As String Dim strSubject As String Dim strMessage As String Set db = CurrentDb() Set rst = db.OpenRecordset("tbl_LoginID", dbOpenDynaset) If Not IsNull(Me.Text_Network_User) Then rst.FindFirst "strEmployeeUserID = '" & Me.Text_Network_User & "'" & " And strEmployeeUserID = '" & Me.Text_Network_User & "'" If rst.NoMatch Then MsgBox "You do not have access to this database!!! " & Chr(13) & _ "Please contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied" 'add the code he strTo= " strSubject = "The subject you want" str Message = "The body of the message" DoCmd.SendObject acSendNoObject, , , strTo, , , strSubject, strMessage DoCmd.Quit Else stDocName = "WelcomeForm" DoCmd.OpenForm stDocName, , , stLinkCriteria End If End If End Sub -- Newbies need extra loven......... |
#6
|
|||
|
|||
Add email VBA to existing code
Oh! I didnt see that... Well it works great except for it I deside not to
send the email and close the email box I get an error and cant close the database error: The SendObject action was canceled. You used a method of the DoCmd object to carry out an action in VB, but hen clicked cancel in a dialog box. For example, you used the Close method to close a changed form, then clicked Cancel in the dialog box that asks if you want to save the changes you made to the form. -- Newbies need extra loven......... "Douglas J. Steele" wrote: It looks as though you missed Arvin's instruction ' add this Dim strTo As String Dim strSubject As String Dim strMessage As String -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Chad" wrote in message ... Thanks for the reply! I get a compile error Variable not Defined and it highlights strTo. Here is the complete code im using if that helps. Maybe I put it in the wrong place..Thanks! Dim db As DAO.Database Dim rst As DAO.Recordset Dim rstV As Recordset Dim stDocName As String Dim stLinkCriteria As String Set db = CurrentDb() Set rst = db.OpenRecordset("tbl_LoginID", dbOpenDynaset) If Not IsNull(Me.Text_Network_User) Then rst.FindFirst "strEmployeeUserID = '" & Me.Text_Network_User & "'" & " And strEmployeeUserID = '" & Me.Text_Network_User & "'" If rst.NoMatch Then MsgBox "You do not have access to this database!!! " & Chr(13) & _ "Please contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied" strTo = " strSubject = "Cant open database" Str Message = "The body of the message" DoCmd.SendObject acSendNoObject, , , strTo, , , strSubject, strMessage DoCmd.Quit Else stDocName = "WelcomeForm" DoCmd.OpenForm stDocName, , , stLinkCriteria End If End If End Sub -- Newbies need extra loven......... "Arvin Meyer [MVP]" wrote: "Chad" wrote in message ... Hello, I am running this code in my WelcomeForm On Open event and when a person is denyed access to the database and before OR after the database closes I would like a outlook email window to come up so they can email me. what and where would I add the code to the code below? Thanks! Private Sub Form_Open(Cancel As Integer) Dim db As DAO.Database Dim rst As DAO.Recordset Dim rstV As Recordset Dim stDocName As String Dim stLinkCriteria As String ' add this Dim strTo As String Dim strSubject As String Dim strMessage As String Set db = CurrentDb() Set rst = db.OpenRecordset("tbl_LoginID", dbOpenDynaset) If Not IsNull(Me.Text_Network_User) Then rst.FindFirst "strEmployeeUserID = '" & Me.Text_Network_User & "'" & " And strEmployeeUserID = '" & Me.Text_Network_User & "'" If rst.NoMatch Then MsgBox "You do not have access to this database!!! " & Chr(13) & _ "Please contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied" 'add the code he strTo= " strSubject = "The subject you want" str Message = "The body of the message" DoCmd.SendObject acSendNoObject, , , strTo, , , strSubject, strMessage DoCmd.Quit Else stDocName = "WelcomeForm" DoCmd.OpenForm stDocName, , , stLinkCriteria End If End If End Sub -- Newbies need extra loven......... |
#7
|
|||
|
|||
Add email VBA to existing code
You'll have to determine the error number, and put in error handling that
ignores that specific error. -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Chad" wrote in message news Oh! I didnt see that... Well it works great except for it I deside not to send the email and close the email box I get an error and cant close the database error: The SendObject action was canceled. You used a method of the DoCmd object to carry out an action in VB, but hen clicked cancel in a dialog box. For example, you used the Close method to close a changed form, then clicked Cancel in the dialog box that asks if you want to save the changes you made to the form. -- Newbies need extra loven......... "Douglas J. Steele" wrote: It looks as though you missed Arvin's instruction ' add this Dim strTo As String Dim strSubject As String Dim strMessage As String -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Chad" wrote in message ... Thanks for the reply! I get a compile error Variable not Defined and it highlights strTo. Here is the complete code im using if that helps. Maybe I put it in the wrong place..Thanks! Dim db As DAO.Database Dim rst As DAO.Recordset Dim rstV As Recordset Dim stDocName As String Dim stLinkCriteria As String Set db = CurrentDb() Set rst = db.OpenRecordset("tbl_LoginID", dbOpenDynaset) If Not IsNull(Me.Text_Network_User) Then rst.FindFirst "strEmployeeUserID = '" & Me.Text_Network_User & "'" & " And strEmployeeUserID = '" & Me.Text_Network_User & "'" If rst.NoMatch Then MsgBox "You do not have access to this database!!! " & Chr(13) & _ "Please contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied" strTo = " strSubject = "Cant open database" Str Message = "The body of the message" DoCmd.SendObject acSendNoObject, , , strTo, , , strSubject, strMessage DoCmd.Quit Else stDocName = "WelcomeForm" DoCmd.OpenForm stDocName, , , stLinkCriteria End If End If End Sub -- Newbies need extra loven......... "Arvin Meyer [MVP]" wrote: "Chad" wrote in message ... Hello, I am running this code in my WelcomeForm On Open event and when a person is denyed access to the database and before OR after the database closes I would like a outlook email window to come up so they can me. what and where would I add the code to the code below? Thanks! Private Sub Form_Open(Cancel As Integer) Dim db As DAO.Database Dim rst As DAO.Recordset Dim rstV As Recordset Dim stDocName As String Dim stLinkCriteria As String ' add this Dim strTo As String Dim strSubject As String Dim strMessage As String Set db = CurrentDb() Set rst = db.OpenRecordset("tbl_LoginID", dbOpenDynaset) If Not IsNull(Me.Text_Network_User) Then rst.FindFirst "strEmployeeUserID = '" & Me.Text_Network_User & "'" & " And strEmployeeUserID = '" & Me.Text_Network_User & "'" If rst.NoMatch Then MsgBox "You do not have access to this database!!! " & Chr(13) & _ "Please contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied" 'add the code he strTo= " strSubject = "The subject you want" str Message = "The body of the message" DoCmd.SendObject acSendNoObject, , , strTo, , , strSubject, strMessage DoCmd.Quit Else stDocName = "WelcomeForm" DoCmd.OpenForm stDocName, , , stLinkCriteria End If End If End Sub -- Newbies need extra loven......... |
#8
|
|||
|
|||
Add email VBA to existing code
how would I find the number? Thanks!
-- Newbies need extra loven......... "Douglas J. Steele" wrote: You'll have to determine the error number, and put in error handling that ignores that specific error. -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Chad" wrote in message news Oh! I didnt see that... Well it works great except for it I deside not to send the email and close the email box I get an error and cant close the database error: The SendObject action was canceled. You used a method of the DoCmd object to carry out an action in VB, but hen clicked cancel in a dialog box. For example, you used the Close method to close a changed form, then clicked Cancel in the dialog box that asks if you want to save the changes you made to the form. -- Newbies need extra loven......... "Douglas J. Steele" wrote: It looks as though you missed Arvin's instruction ' add this Dim strTo As String Dim strSubject As String Dim strMessage As String -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Chad" wrote in message ... Thanks for the reply! I get a compile error Variable not Defined and it highlights strTo. Here is the complete code im using if that helps. Maybe I put it in the wrong place..Thanks! Dim db As DAO.Database Dim rst As DAO.Recordset Dim rstV As Recordset Dim stDocName As String Dim stLinkCriteria As String Set db = CurrentDb() Set rst = db.OpenRecordset("tbl_LoginID", dbOpenDynaset) If Not IsNull(Me.Text_Network_User) Then rst.FindFirst "strEmployeeUserID = '" & Me.Text_Network_User & "'" & " And strEmployeeUserID = '" & Me.Text_Network_User & "'" If rst.NoMatch Then MsgBox "You do not have access to this database!!! " & Chr(13) & _ "Please contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied" strTo = " strSubject = "Cant open database" Str Message = "The body of the message" DoCmd.SendObject acSendNoObject, , , strTo, , , strSubject, strMessage DoCmd.Quit Else stDocName = "WelcomeForm" DoCmd.OpenForm stDocName, , , stLinkCriteria End If End If End Sub -- Newbies need extra loven......... "Arvin Meyer [MVP]" wrote: "Chad" wrote in message ... Hello, I am running this code in my WelcomeForm On Open event and when a person is denyed access to the database and before OR after the database closes I would like a outlook email window to come up so they can me. what and where would I add the code to the code below? Thanks! Private Sub Form_Open(Cancel As Integer) Dim db As DAO.Database Dim rst As DAO.Recordset Dim rstV As Recordset Dim stDocName As String Dim stLinkCriteria As String ' add this Dim strTo As String Dim strSubject As String Dim strMessage As String Set db = CurrentDb() Set rst = db.OpenRecordset("tbl_LoginID", dbOpenDynaset) If Not IsNull(Me.Text_Network_User) Then rst.FindFirst "strEmployeeUserID = '" & Me.Text_Network_User & "'" & " And strEmployeeUserID = '" & Me.Text_Network_User & "'" If rst.NoMatch Then MsgBox "You do not have access to this database!!! " & Chr(13) & _ "Please contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied" 'add the code he strTo= " strSubject = "The subject you want" str Message = "The body of the message" DoCmd.SendObject acSendNoObject, , , strTo, , , strSubject, strMessage DoCmd.Quit Else stDocName = "WelcomeForm" DoCmd.OpenForm stDocName, , , stLinkCriteria End If End If End Sub -- Newbies need extra loven......... |
#9
|
|||
|
|||
Add email VBA to existing code
Start by adding standard error handling.
At the top of the module (right after the "Private Sub Form_Open()"), put On Error GoTo Err_Form_Open At the end of the module (right before the "End Sub"), put End_Form_Open: Exit Sub Err_Form_Open: MsgBox Err.Number & ": " & Err.Description Resume End_Form_Open Now when you run the code, you'll get a message box with a number, followed by a colon, followed by your error message. Once you know the error number, change the last bit of code to End_Form_Open: Exit Sub Err_Form_Open: Select Case Err.Number Case xxx ' Whatever error number you got above Resume Next Case Else MsgBox Err.Number & ": " & Err.Description Resume End_Form_Open End Select -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Chad" wrote in message ... how would I find the number? Thanks! -- Newbies need extra loven......... "Douglas J. Steele" wrote: You'll have to determine the error number, and put in error handling that ignores that specific error. -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Chad" wrote in message news Oh! I didnt see that... Well it works great except for it I deside not to send the email and close the email box I get an error and cant close the database error: The SendObject action was canceled. You used a method of the DoCmd object to carry out an action in VB, but hen clicked cancel in a dialog box. For example, you used the Close method to close a changed form, then clicked Cancel in the dialog box that asks if you want to save the changes you made to the form. -- Newbies need extra loven......... "Douglas J. Steele" wrote: It looks as though you missed Arvin's instruction ' add this Dim strTo As String Dim strSubject As String Dim strMessage As String -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Chad" wrote in message ... Thanks for the reply! I get a compile error Variable not Defined and it highlights strTo. Here is the complete code im using if that helps. Maybe I put it in the wrong place..Thanks! Dim db As DAO.Database Dim rst As DAO.Recordset Dim rstV As Recordset Dim stDocName As String Dim stLinkCriteria As String Set db = CurrentDb() Set rst = db.OpenRecordset("tbl_LoginID", dbOpenDynaset) If Not IsNull(Me.Text_Network_User) Then rst.FindFirst "strEmployeeUserID = '" & Me.Text_Network_User & "'" & " And strEmployeeUserID = '" & Me.Text_Network_User & "'" If rst.NoMatch Then MsgBox "You do not have access to this database!!! " & Chr(13) & _ "Please contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied" strTo = " strSubject = "Cant open database" Str Message = "The body of the message" DoCmd.SendObject acSendNoObject, , , strTo, , , strSubject, strMessage DoCmd.Quit Else stDocName = "WelcomeForm" DoCmd.OpenForm stDocName, , , stLinkCriteria End If End If End Sub -- Newbies need extra loven......... "Arvin Meyer [MVP]" wrote: "Chad" wrote in message ... Hello, I am running this code in my WelcomeForm On Open event and when a person is denyed access to the database and before OR after the database closes I would like a outlook email window to come up so they can me. what and where would I add the code to the code below? Thanks! Private Sub Form_Open(Cancel As Integer) Dim db As DAO.Database Dim rst As DAO.Recordset Dim rstV As Recordset Dim stDocName As String Dim stLinkCriteria As String ' add this Dim strTo As String Dim strSubject As String Dim strMessage As String Set db = CurrentDb() Set rst = db.OpenRecordset("tbl_LoginID", dbOpenDynaset) If Not IsNull(Me.Text_Network_User) Then rst.FindFirst "strEmployeeUserID = '" & Me.Text_Network_User & "'" & " And strEmployeeUserID = '" & Me.Text_Network_User & "'" If rst.NoMatch Then MsgBox "You do not have access to this database!!! " & Chr(13) & _ "Please contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied" 'add the code he strTo= " strSubject = "The subject you want" str Message = "The body of the message" DoCmd.SendObject acSendNoObject, , , strTo, , , strSubject, strMessage DoCmd.Quit Else stDocName = "WelcomeForm" DoCmd.OpenForm stDocName, , , stLinkCriteria End If End If End Sub -- Newbies need extra loven......... |
#10
|
|||
|
|||
Add email VBA to existing code
This is weird? I am now working on it at home on Vista and it wors great but
my PC at work is using XP and thats the one I get the error on. It says im still running or have open a DAO and simething else and thats why it wouldnt close..Any ideas? Thanks -- Newbies need extra loven......... "Chad" wrote: how would I find the number? Thanks! -- Newbies need extra loven......... "Douglas J. Steele" wrote: You'll have to determine the error number, and put in error handling that ignores that specific error. -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Chad" wrote in message news Oh! I didnt see that... Well it works great except for it I deside not to send the email and close the email box I get an error and cant close the database error: The SendObject action was canceled. You used a method of the DoCmd object to carry out an action in VB, but hen clicked cancel in a dialog box. For example, you used the Close method to close a changed form, then clicked Cancel in the dialog box that asks if you want to save the changes you made to the form. -- Newbies need extra loven......... "Douglas J. Steele" wrote: It looks as though you missed Arvin's instruction ' add this Dim strTo As String Dim strSubject As String Dim strMessage As String -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Chad" wrote in message ... Thanks for the reply! I get a compile error Variable not Defined and it highlights strTo. Here is the complete code im using if that helps. Maybe I put it in the wrong place..Thanks! Dim db As DAO.Database Dim rst As DAO.Recordset Dim rstV As Recordset Dim stDocName As String Dim stLinkCriteria As String Set db = CurrentDb() Set rst = db.OpenRecordset("tbl_LoginID", dbOpenDynaset) If Not IsNull(Me.Text_Network_User) Then rst.FindFirst "strEmployeeUserID = '" & Me.Text_Network_User & "'" & " And strEmployeeUserID = '" & Me.Text_Network_User & "'" If rst.NoMatch Then MsgBox "You do not have access to this database!!! " & Chr(13) & _ "Please contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied" strTo = " strSubject = "Cant open database" Str Message = "The body of the message" DoCmd.SendObject acSendNoObject, , , strTo, , , strSubject, strMessage DoCmd.Quit Else stDocName = "WelcomeForm" DoCmd.OpenForm stDocName, , , stLinkCriteria End If End If End Sub -- Newbies need extra loven......... "Arvin Meyer [MVP]" wrote: "Chad" wrote in message ... Hello, I am running this code in my WelcomeForm On Open event and when a person is denyed access to the database and before OR after the database closes I would like a outlook email window to come up so they can me. what and where would I add the code to the code below? Thanks! Private Sub Form_Open(Cancel As Integer) Dim db As DAO.Database Dim rst As DAO.Recordset Dim rstV As Recordset Dim stDocName As String Dim stLinkCriteria As String ' add this Dim strTo As String Dim strSubject As String Dim strMessage As String Set db = CurrentDb() Set rst = db.OpenRecordset("tbl_LoginID", dbOpenDynaset) If Not IsNull(Me.Text_Network_User) Then rst.FindFirst "strEmployeeUserID = '" & Me.Text_Network_User & "'" & " And strEmployeeUserID = '" & Me.Text_Network_User & "'" If rst.NoMatch Then MsgBox "You do not have access to this database!!! " & Chr(13) & _ "Please contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied" 'add the code he strTo= " strSubject = "The subject you want" str Message = "The body of the message" DoCmd.SendObject acSendNoObject, , , strTo, , , strSubject, strMessage DoCmd.Quit Else stDocName = "WelcomeForm" DoCmd.OpenForm stDocName, , , stLinkCriteria End If End If End Sub -- Newbies need extra loven......... |
Thread Tools | |
Display Modes | |
|
|