A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Add email VBA to existing code



 
 
Thread Tools Display Modes
  #1  
Old September 13th, 2007, 02:26 PM posted to microsoft.public.access.gettingstarted
chad
external usenet poster
 
Posts: 631
Default 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  
Old September 13th, 2007, 02:44 PM posted to microsoft.public.access.gettingstarted
Chris Reveille
external usenet poster
 
Posts: 93
Default 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  
Old September 13th, 2007, 03:43 PM posted to microsoft.public.access.gettingstarted
Arvin Meyer [MVP]
external usenet poster
 
Posts: 4,231
Default 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  
Old September 13th, 2007, 05:02 PM posted to microsoft.public.access.gettingstarted
chad
external usenet poster
 
Posts: 631
Default 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  
Old September 13th, 2007, 05:32 PM posted to microsoft.public.access.gettingstarted
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default 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  
Old September 13th, 2007, 07:02 PM posted to microsoft.public.access.gettingstarted
chad
external usenet poster
 
Posts: 631
Default 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  
Old September 13th, 2007, 08:11 PM posted to microsoft.public.access.gettingstarted
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default 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
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.........








  #8  
Old September 13th, 2007, 08:32 PM posted to microsoft.public.access.gettingstarted
chad
external usenet poster
 
Posts: 631
Default 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
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.........









  #9  
Old September 13th, 2007, 08:41 PM posted to microsoft.public.access.gettingstarted
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default 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
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.........











  #10  
Old September 13th, 2007, 08:42 PM posted to microsoft.public.access.gettingstarted
chad
external usenet poster
 
Posts: 631
Default 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
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.........









 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:01 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.