Access 2010 using DoCmd.SendObject to send email - ms-access-2010

Using Access 2010, I have created a form that is functioning as a directory. I want to be able to click on a name field and send an email to that person. I have it working for one name on the directory but the second and third names fields give me the following error: Compile error: Method or data member not found. The highlighted portion of the code is: Private Sub AA2Name_Click(), while Me.AA2Email is highlighted in blue.
The full code is:
Private Sub AA1Name_Click()
On Error GoTo Err_Handler
DoCmd.SendObject acSendNoObject, To:=Me.AA1Email
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & " - " & Err.Description
End If
Resume Exit_Handler
End Sub
Private Sub AA2Name_Click()
On Error GoTo Err_Handler
DoCmd.SendObject acSendNoObject, To:=Me.AA2Email
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & " - " & Err.Description
End If
Resume Exit_Handler
End Sub
Private Sub AA3Name_Click()
On Error GoTo Err_Handler
DoCmd.SendObject acSendNoObject, To:=Me.AA3Email
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & " - " & Err.Description
End If
Resume Exit_Handler
End Sub
Thank you to anyone that can help!

I've recreated as best I can what from you've described above and it all ran ok for me. You can have a look at what I've got here for clues; use the frmEmails - original VBA form.
The only thing I can think of is that you may have mistyped Me.AA2Email somewhere? Perhaps check the Name property of the control this is meant to refer to... does it appear in intellisense?
On a side note: I've created another version of the same form in that file called frmEmails - updated VBA. Here I've arranged your VBA so you're not duplicating so much code. Essentially it runs all the common code in to 1 subroutine, passing in the varying email field as an argument. This doesn't solve your problem, but I thought it was worth adding.
Public Sub ComposeEmail(ToField As String)
On Error GoTo Err_Handler
DoCmd.SendObject acSendNoObject, To:=ToField
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & " - " & Err.Description
End If
Resume Exit_Handler
End Sub
Private Sub AA1Email_Click()
ComposeEmail Me.AA1Email
End Sub
Private Sub AA2Email_Click()
ComposeEmail Me.AA2Email
End Sub
Private Sub AA3Email_Click()
ComposeEmail Me.AA3Email
End Sub

Related

Button Event isn't displaying value until 2nd click (vb6)

I created a tcp connection in vb6 to grab the weight off of a scale and display that weight after pressing a button. The problem is that the weight is not displayed until the SECOND (2nd) click of the button, not the first. I have set a break point in various spots and upon the first click of the button, it takes me to that break point, so I know the event is firing as it should, but nothing is displayed until the 2nd click. I have done a bunch of research but can't seem to find anyone with the exact problem (or solution).
Public tcpC As New Winsock
'Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub CFixPicture_Close()
tcpC.Close
End Sub
Private Sub CFixPicture_Initialize()
tcpC.LocalPort = 0
tcpC.Connect "192.168.0.1", 8000
End Sub
Private Sub CommandButton1_click()
On Error GoTo errHandler
Dim strData As String
tcpC.SendData "S" & vbCrLf
tcpC.GetData strData
Text1.Caption = "Weight: " & strData
Exit Sub
errHandler:
MsgBox "error:" & Err.Description
End Sub
I am making an assumption that your code is in the form and you are just declaring a new object of type Winsock. My code declares a Winsock variable using the keyword WithEvents to get access to the events raised by the Winsock object. The particular event you're interested in is DataArrival. It is fired by the Winsock control when data is received. I moved setting the text to this event. Also, you cannot use WithEvents and "As New" (you really don't want to use As New anyway), so I create the object before I set the properties in the CFixPicture_Initialize() method. Finally, I added setting the object to nothing after closing it.
Option Explicit
Private WithEvents tcpC As Winsock
Private Sub CFixPicture_Close()
tcpC.Close
Set tcpP = Nothing
End Sub
Private Sub CFixPicture_Initialize()
Set tcpC = New Winsock
tcpC.LocalPort = 0
tcpC.Connect "192.168.0.1", 8000
End Sub
Private Sub CommandButton1_click()
On Error GoTo errHandler
Dim strData As String
tcpC.SendData "S" & vbCrLf
'there is no data here yet - moved to the DataArrival event
'tcpC.GetData strData
'Text1.Caption = "Weight: " & strData
Exit Sub
errHandler:
MsgBox "error:" & Err.Description
End Sub
Private Sub tcpC_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
tcpC.GetData strData
Text1.Caption = "Weight: " & strData
End Sub

vb.net if else logic flow error

I am debugging some code in an ASP.net web application project.
I have an If/Else statement nested in a Try/Catch block. Whenever an error occurs within the If block, rather than immediately jumping into the Catch block, it falls into the Else block.
I have stepped through the code repeatedly to witness this happening. When I throw an exception within the if block, I would expect logic to flow into the catch block, and I would never expect to see the if block get hit, and then the else block get hit, that seems to completely defeat the purpose of the if/else logic.
Here is the code in question:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
LoadDocument()
End Sub
Private Sub LoadDocument()
Dim taDocuments As New SecureTableAdapters.IndividualDocumentsTableAdapter
Dim dtDocuments As New Secure.IndividualDocumentsDataTable
Dim iDocumentID As Integer = CInt(Request.QueryString("iDocumentID"))
Dim sFileName As String
Dim isMac As Boolean = clsApplication.isMac(Request.Browser.Platform)
Dim bDownloaded As Boolean = False
Try
If taDocuments.FillBy_IndividualDocumentID(dtDocuments, iDocumentID) > 0 Then
Dim oRow As Secure.IndividualDocumentsRow = dtDocuments.Rows(0)
sFileName = "Statement-" & oRow.sFileNumber & ".pdf"
If oRow.sDocumentName.ToUpper.Contains("LEDES") Or oRow.sDocumentName.ToUpper.Contains("TEXT") Then
sFileName = sFileName.Replace("pdf", "txt")
End If
Dim b As Byte() = Nothing
If oRow.IsbExtractedNull = False AndAlso oRow.bExtracted Then
Dim sHost As String = "206.220.201.175"
Dim sPath As String = String.Format("/Legacy/{0}/{1}/{2}.pdf", oRow.iFirmID.ToString, "Individuals", oRow.iIndividualDocumentID.ToString)
b = DownloadDocument(sHost, sPath)
If b Is Nothing Then
'When this line is hit, logic jumps to the else block with the comment below
Throw New Exception("FTP Download Failed")
Else
bDownloaded = True
End If
Else
bDownloaded = False
End If
If bDownloaded = False Then
b = getImage(iDocumentID, "oPDF", "iIndividualDocumentID", "tblIndividualDocuments")
If b Is Nothing Then
Throw New Exception
End If
End If
If isMac Then
Response.ContentType = "application/x-macbinary"
Else
Response.ContentType = "application/octet-stream"
End If
Response.Expires = 0
Response.AddHeader("Content-Disposition", "attachment; filename=""" & sFileName & """")
Response.BinaryWrite(b)
Else
'--->When the exception occurs, logic jumps to this else block
Throw New Exception
End If
Catch ex As Exception
Response.Write("Sorry, that statement could not be located. Please try again, or call us at xxx.xxx.xxxx for further information.")
clsApplication.EmailError("An error occurred downloading a statement: " & vbCrLf & ex.Source & vbCrLf & ex.Message & vbCrLf & ex.StackTrace)
End Try
End Sub
How is this possible?
It sounds like you're using the debugger with Optimizations still turned on. This can cause the Step Traceing to act in seemingly illogical and even impossible ways. This is caused because after the optimizer moves the code and variables around and consolidates different statements, there is no longer a simple or straight-forward relationship between the lines of source-code and the executable instructions.
Sounds like the code you're debugging against might be out of sync with the code that's executing. Try rebuilding the whole solution.
I think you are probably mistaken:
Try the following in simple vb .net winforms program.
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Try
Dim doIt As Boolean = True
If doIt Then
Throw New Exception("throwing that stuff")
Else
MsgBox("in here - how did that happen?")
End If
Catch ex As Exception
MsgBox(String.Format("That makes sense. Exception is: {0}", ex))
End Try
End Sub
End Class

CSocket - DataArrival Not Occurring (GET Request)

I'm attempting to do a GET request in VB6 using CSocket. The data is sent successfully however no response is received (tested on multiple sites). My code is below.
Option Explicit
Dim WithEvents WinSock As CSocket
Private Sub Form_Load()
Set WinSock = New CSocket
End Sub
Private Sub btnConnect_Click()
WinSock.Protocol = sckTCPProtocol
WinSock.Connect "winhome.de", 80
MsgBox "Connecting..."
End Sub
Private Sub WinSock_OnConnect()
MsgBox "Connected."
Dim Data$
Data = "GET http://www.winhome.de/index.html HTTP/1.0" & vbCrLf & "Accept: */*" & _
vbCrLf & "Accept: text/html" & vbCrLf & vbCrLf
WinSock.SendData Data
MsgBox Data
End Sub
Private Sub WinSock_OnDataArrival(ByVal bytesTotal As Long)
Dim Data$
WinSock.GetData Data, vbString
MsgBox Data
End Sub
The OnConnect event never seems to trigger, but works fine with a normal WinSock control, Any help?
For these scenarios you don't want any "blocking" debugging, including MsgBox or IDE breaks -- the events get lost.
E.g. accumulate your debug logs into a string or a file and look at the results after a run.

Asp.net Vbscript Error

Please tell me where I have gone wrong in this script. I am getting this error.
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30002: Type 'ProcessStartInfo' is not defined.
Source Error:
Line 5: Public Shared Function ExecuteCommand(Command As String, Timeout As Integer) As Integer
Line 6: Dim ExitCode As Integer
*Line 7: Dim ProcessInfo As ProcessStartInfo*
Line 8: Dim Process As Process
Line 9:
Source File: C:\Inetpub\wwwroot\ServiceFileUploadRE.aspx Line: 7
The Script:
<%# Page Language=VBScript %>
<script runat="server">
Public Shared Function ExecuteCommand(Command As String, Timeout As Integer) As Integer
Dim ExitCode As Integer
Dim ProcessInfo As ProcessStartInfo
Dim Process As Process
ProcessInfo = New ProcessStartInfo("cmd.exe", "/C " + Command)
ProcessInfo.CreateNoWindow = True
ProcessInfo.UseShellExecute = False
Process = Process.Start(ProcessInfo)
Process.WaitForExit(Timeout)
ExitCode = Process.ExitCode
Process.Close()
Return ExitCode
End Function
Protected Sub Button1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs)
If FileUpload1.HasFile Then
Try
FileUpload1.SaveAs("C:\Inetpub\wwwroot\upload\" & _
FileUpload1.FileName)
Label1.Text = "File name: " & _
FileUpload1.PostedFile.FileName & "<br>" & _
"File Size: " & _
FileUpload1.PostedFile.ContentLength & " kb<br>" & _
"Content type: " & _
FileUpload1.PostedFile.ContentType
Catch ex As Exception
Label1.Text = "ERROR: " & ex.Message.ToString()
End Try
Else
Label1.Text = "You have not specified a file."
End If
End Sub
ExecuteCommand("REN C:\Document.rtf YES.rtf",100)
</script>
.......
Maybe place the line
<%# Import Namespace = "System.Diagnostics" %>
directly after <% Page....
If that does not work, then check whether you are using .NET Framework 4.

VB.NET Custom Errors Messages

I like to user custom errors in my site.
The Idea is to trap errors and display friendly meaningful messages to users.
The real error details (line number, Page ...) will sent to me by e-mail.
I am programming in VB.NET.
Until now every code that i found about this say's that i must use the global.asax for it.
I do not like to use global.asax, I just like to make an error page that will sent me a -email with all the error details.
Until now, i go to the web.config file and insert this line:
<customErrors defaultRedirect="test.aspx" mode="On"></customErrors>
test.aspx looks like this:
Sub Page_Error(sender as Object, e as EventArgs)
Dim ctxOBJ As HttpContext
Dim exceptionOBJ As Exception
Dim errorInfoTXT As String
ctxOBJ = HttpContext.Current()
exceptionOBJ = ctxOBJ.Server.GetLastError()
errorInfoTXT = "Offending URL: " & ctxOBJ.Request.Url.ToString() & _
"Source: " & exceptionOBJ.Source.ToString() & _
"Message: " & exceptionOBJ.Message.ToString() & _
"Stack trace: " & exceptionOBJ.StackTrace.ToString() & _
"Target Site: " & exceptionOBJ.TargetSite.ToString()
ctxOBJ.Response.Write (errorInfoTXT)
ctxOBJ.Server.ClearError ()
End Sub
When here is an error in some page its redirect me to test.aspx but not showing any error.
Thanks,
Roy Shoa.
You just need to change this to
Sub Page_Load(sender as Object, e as EventArgs)
It's not the error page that's erroring, so its error event never fires.

Resources