Referencing Form Fields

karl009

Registered User.
Local time
Today, 01:25
Joined
Mar 2, 2010
Messages
55
Hi,

I have built a small application to send emails in C#, I am now trying to get it to work in Access.

If the email address are hard coded into the C# app and a button pressed in Access the emails will send.

I have changed the C# app to accept arguments ie a To and CC email addresses.

I am having trouble referencing fields on a form where the email addresses are stored I have made an attempt at it but have been unable to complete it.

If the program where executed from DOS the command would be;
SendEmail.exe karl12@mailsever.com paul32@mailserver.com

This is what I am trying to replicate in the VBA of access when a button is clicked.

Code:
Private Sub SendMail_Click()
On Error GoTo Err_SendMail_Click

    Dim stAppName As String
    
    Dim stEmailTo As String
    Dim stEmailCC As String
    
    Forms![AddressBook]![Email] = stEmailTo.Value
    Forms![AddressBook]![CC] = stEmailCC.Value
    
    stAppName = "C:\Users\karl\Documents\Visual Studio 2008\Projects\SendEmail v1\SendEmail\bin\Debug\SendEmail.exe"
    
    
    Call Shell(stAppName + stEmailTo + stEmailCC, 1)

Exit_SendMail_Click:
    Exit Sub

Err_SendMail_Click:
    MsgBox Err.Description
    Resume Exit_SendMail_Click
    
End Sub

Thanks for any help on this...
Karl
 
Will you reveal what specific problem you have? Or do you wish to leave the guessing to the reader?
 
Hiya,

When I call the Shell command "strAppName" which is to the program location it will work, when I try and add in references to feilds\values within the form am unsure how to proceed.

This is how I have tried to reference the feilds and data.
Dim stEmailTo As String
Dim stEmailCC As String
Forms![AddressBook]! = stEmailTo.Value
Forms![AddressBook]![CC] = stEmailCC.Value

After which I combied the program locations and the arguments;
Call Shell(stAppName + stEmailTo + stEmailCC, 1)

Where have I gone wrong?
Many Thanks
Karl
 
1. Assignments operations in VBA procede from right to left, like any other language, so you need to swap the strings and the references to form controls.

2. As far as I know, a string is a string, so no StringName.Value-business is necessary. Drop the ".value"

3. Concatentation of strings in VBA is accomplished using the ampersand &, not +, which does something slightly different

4. Shell hates paths with spaces. Instead of stAppName you need to feed it with Chr(34) & stAppName & Chr(34), which wraps the path in double quotes

5. shell commands nad parameters arte normally separated by spaces or whatever your app wants - I don't see any in your statement

6. Don't do all at once: make a string with what you want to tell the shell to be able to inspect it:

Dim myShellCommand as String
Dim ret
myShellCommand= string1 & " " & string 2 ....

debug.print myShellCommand

ret=Shell(myShellCommand)
 
Last edited:

Users who are viewing this thread

Back
Top Bottom