473,395 Members | 2,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Trying to create an email with form data.


Hi I'm having trouble writing to an excel spreadsheet.
I have the following code

Dim strList As String
With Me.trainingplan.Form.RecordsetClone
.MoveFirst
While Not .EOF
strList = strList & vbCrLf & Nz(.Fields("Course"))
.MoveNext
Wend
End With

This loops to store all the values in Course on a Continuous Form.

i Now want to email this data. I tried to put this into an email as
text but it didnt take the vbCrLf and ended up as one big long line of
text. I tried an email as html as well using <BR>/ But that didnt work
either.

So now i'm trying to put this data into an excel spreadsheet first.

I'm using the following...

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, strList,
"C:\Courses.xls"

i thought that i'd be able to write out the variable. But this doesnt
work.

Please someone help!
Many thanks in advance.

Nov 13 '05 #1
5 1492
<si************@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...

Hi I'm having trouble writing to an excel spreadsheet.
I have the following code

Dim strList As String
With Me.trainingplan.Form.RecordsetClone
.MoveFirst
While Not .EOF
strList = strList & vbCrLf & Nz(.Fields("Course"))
.MoveNext
Wend
End With

This loops to store all the values in Course on a Continuous Form.

i Now want to email this data. I tried to put this into an email as
text but it didnt take the vbCrLf and ended up as one big long line of
text. I tried an email as html as well using <BR>/ But that didnt work
either.

So now i'm trying to put this data into an excel spreadsheet first.

I'm using the following...

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, strList,
"C:\Courses.xls"

i thought that i'd be able to write out the variable. But this doesnt
work.

Please someone help!
Many thanks in advance.

By all means use an Excel spreadsheet if you prefer, but not as a
second-rate alternative. I can't see why the vbCrLf does not give you new
lines. Probably because you don't say how you are generating the e-mail or
what e-mail client you have. The simplest (and most limited) way to send an
e-mail is DoCmd.SendObject and here I have made a simple list. On my
machine with Outlook XP this generates an e-mail with three separate lines
in it.
Why not post your code?

Private Sub cmdEmail_Click()

On Error GoTo Err_Handler

Dim strList As String

strList = "One" & vbCrLf & "Two" & vbCrLf & "Three"

DoCmd.SendObject , , , , , , , strList

Exit_Handler:
Exit Sub

Err_Handler:

Select Case Err.Number

Case 2501 'E-mail cancelled - ignore this

Case Else
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number

End Select

Resume Exit_Handler

End Sub

Nov 13 '05 #2
Hi I'm getting there now.

I've created a query called Query Training Plan. For the field "Name"
in the criteria section i have [Enter Staff Name]

Now when i click a button on my form i call the code below. The only
problem i now have is i dont want to enter the Staff Name. I want to
just pass this to the query from the current record being viewed.
here's my code.

Private Sub Command0_Click()
On Error GoTo Err_Command0_Click

sAddedtext = sAddedtext & "&Subject=" & "Training Plan"
sAddedtext = sAddedtext & "&Body=" & strList
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Query
Training Plan", "C:\Test.xls"
sAddedtext = sAddedtext & "Attach=" & Chr$(34) & "C:\test.xls" &
Chr$(34)
Debug.Print strList

stext = "mailto:" & stext

If Len(sAddedtext) <> 0 Then
Mid$(sAddedtext, 1, 1) = "?"
End If

stext = stext & sAddedtext
'MsgBox stext

' launch default e-mail program
If Len(stext) Then
Call rubbish(hwnd, "open", stext, vbNullString,
vbNullString, 1)
End If
Exit_Command0_Click:
Exit Sub
Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
End Sub

Nov 13 '05 #3
Email client is outlook.

The none excel method looked like this...
Dim strList As String
With Me.trainingplan.Form.RecordsetClone
.MoveFirst
While Not .EOF
strList = strList & vbCrLf & Nz(.Fields("Course"))
.MoveNext
Wend
End With

sAddedtext = sAddedtext & "&Subject=" & "Training Plan"
sAddedtext = sAddedtext & "&Body=" & strList

stext = "mailto:" & stext

Nov 13 '05 #4

<si************@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Email client is outlook.

The none excel method looked like this...
Dim strList As String
With Me.trainingplan.Form.RecordsetClone
.MoveFirst
While Not .EOF
strList = strList & vbCrLf & Nz(.Fields("Course"))
.MoveNext
Wend
End With

sAddedtext = sAddedtext & "&Subject=" & "Training Plan"
sAddedtext = sAddedtext & "&Body=" & strList

stext = "mailto:" & stext

Sorry for the delay - suddenly called away.
I know how you build up the list, but how do you generate the e-mail? In my
earlier example, I show one method using DoCmd.SendObject, but I guess you
are doing something different.
strList = "One" & vbCrLf & "Two" & vbCrLf & "Three"
DoCmd.SendObject , , , , , , , strList

With the Excel method, you can change the design of the query, so instead of
prompting you for the Staff Name parameter it reads it from the form. You
do this by changing the criteria
from [Enter the Staff Name]
to Forms![My Form]![Staff Name]
or whatever your form is called.

Nov 13 '05 #5

<si************@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Email client is outlook.

The none excel method looked like this...
Dim strList As String
With Me.trainingplan.Form.RecordsetClone
.MoveFirst
While Not .EOF
strList = strList & vbCrLf & Nz(.Fields("Course"))
.MoveNext
Wend
End With

sAddedtext = sAddedtext & "&Subject=" & "Training Plan"
sAddedtext = sAddedtext & "&Body=" & strList

stext = "mailto:" & stext

Would you consider the DoCmd.SendObject method of sending an e-mail instead
of Call rubbish(hwnd, "open", stext, vbNullString, vbNullString, 1) as per
previous example.

Private Sub cmdEmail_Click()

On Error GoTo Err_Handler

Dim strList As String

strList = "One" & vbCrLf & "Two" & vbCrLf & "Three"

DoCmd.SendObject , , , , , , , strList

Exit_Handler:
Exit Sub

Err_Handler:

Select Case Err.Number

Case 2501 'E-mail cancelled - ignore this

Case Else
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number

End Select

Resume Exit_Handler

End Sub
With the Excel method, you can change the design of the query, so instead of
prompting you for the Staff Name parameter it reads it from the form. You
do this by changing the criteria
from [Enter the Staff Name]
to Forms![My Form]![Staff Name]
or whatever your form is called.

Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: apchar | last post by:
I am trying to use php as a kind of servlet to act as a middle man between a java applet and mysql. I know java has jdbc but it's flakey and painful. php access to mysql is much nicer. So I have:...
1
by: Dave | last post by:
I have a form which is based on a table (a) with over 6000 records.I have a button on this form which will open another form with related data from another table (b). What I want to do is open the...
18
by: Gleep | last post by:
I've searched google intensely on this topic and it seems noone really knows how to approch this. The goal I don't want clients to give out their usernames and passwords to friends, since the site...
0
by: Kristian Frost | last post by:
Hi, I'm just getting started with VB.Net, and I'm having trouble getting the routing around of some of the data straight in my mind, which has led me to the following problem. Basically, I'm...
6
by: AppleBag | last post by:
I'm having the worst time trying to login to myspace through code. Can someone tell me how to do this? Please try it yourself before replying, only because I have asked this a couple of times in...
6
by: Boldgeek | last post by:
I am trying to develop an app that will allow automatic updating of a web form which uses multipart/form-data enctype (as it MIGHT be sending an image) I have an example form, which when...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
2
by: Henry Stock | last post by:
I don't seem to understand how to use the value: Request.ServerVariables("remote_addr") I am trying to pass the ip address of a sending web client in the body of an email message. When I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.