473,396 Members | 2,037 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,396 software developers and data experts.

Referencing a subform control for email

I have a form on which there is a tabcontrol and on this onr of the tabpages
is a tick box which opens Outlook with data
from the main form and prompts the user to amend the message before being
sent.
The code is
Private Sub Loadtxt_Click()
Dim oA As Outlook.Application
Dim oM As Outlook.MailItem
Set oA = CreateObject("Outlook.Application")
Set oM = oA.CreateItem(olMailItem)
If Me!Loadtxt = True Then
oM.Subject = "Upload to Online " & Me.Docnumtxt
oM.Body = "Please upload this document to Online " & vbCrLf & "Document
Number: " & Me.Docnumtxt & vbCrLf & "Author: " & " " & Me.DocAuthortxt &
vbCrLf & "Document URL: " & " " & Me.DocURLtxt
'then you can send it
'oM.Send

' or display it for editing
oM.Display
End If
End Sub

On the tab control is a subform called
tblDocSubjectssubform which has a control called cmbPsubject. I want to
include in the email the value of this control and have used this code
& me.tblDocSubjectssubform(cmbPSubject) but it doesn't work. How can I
reference the control on the subform?

TIA
Tony Williams
Nov 12 '05 #1
5 2570
Tony,
there's a really good article on www.mvps.org that you can download
that Keri Hardwick wrote that gives examples of referencing controls
on forms, subforms, subsubforms etc right here...
http://www.mvps.org/access/forms/frm0031.htm

The only problem I see with this is that you're going to have more
than one possible subject if you have a subform... are you just going
to grab the value from the first record?

HTH,
Pieter
Nov 12 '05 #2
Thanks Pieter, in answer to your question that is the problem. I've managed
to work out the syntax for the oM.Body and yhis is what I've got now
oM.Body = "Please upload this document to Online " & vbCrLf & vbCrLf &
"Document Number: " & Me.Docnumtxt & vbCrLf & "Document Name: " &
Me.DocNametxt & vbCrLf & "Author: " & " " & Me.DocAuthortxt & vbCrLf &
"Document URL: " & " " & Me.DocURLtxt & vbCrLf & "Primary Code: " &
Forms![frmdocumentrecord]![tblDocSubjectssubform].Form![DocPSubjecttxt] &
vbCrLf & "Secondary Code: " &
Forms![frmdocumentrecord]![tblDocSubjectssubform].Form![cmbSSubject]

However because tblDocSubjectssubform is in continuous format I'm only
picking up the first record when I need to pick all the data. Any ideas?
TIA
Tony
"Pieter Linden" <pi********@hotmail.com> wrote in message
news:bf**************************@posting.google.c om...
Tony,
there's a really good article on www.mvps.org that you can download
that Keri Hardwick wrote that gives examples of referencing controls
on forms, subforms, subsubforms etc right here...
http://www.mvps.org/access/forms/frm0031.htm

The only problem I see with this is that you're going to have more
than one possible subject if you have a subform... are you just going
to grab the value from the first record?

HTH,
Pieter

Nov 12 '05 #3
Kind of guessing now, but how about opening a RecordsetClone of the
subform's underlying recordsource and then looping through that and
going that way. Something like:

dim rs as dao.recordset
set rs = me!frmSub.RecordsetClone

do until rs.eof
'do your appending here
rs.movenext
loop
Nov 12 '05 #4
Thanks for that suggestion Pieter but being a novice at coding that has me
lost! It is the "do your appending here that loses me what exactly does that
mean?
TIA
Tony
"Pieter Linden" <pi********@hotmail.com> wrote in message
news:bf**************************@posting.google.c om...
Kind of guessing now, but how about opening a RecordsetClone of the
subform's underlying recordsource and then looping through that and
going that way. Something like:

dim rs as dao.recordset
set rs = me!frmSub.RecordsetClone

do until rs.eof
'do your appending here
rs.movenext
loop

Nov 12 '05 #5
"Tony Williams" <tw@tcp.invalid> wrote in message
news:bt**********@sparta.btinternet.com...
Thanks for that suggestion Pieter but being a novice at coding that has me
lost! It is the "do your appending here that loses me what exactly does that mean?
TIA
Tony
"Pieter Linden" <pi********@hotmail.com> wrote in message
news:bf**************************@posting.google.c om...
Kind of guessing now, but how about opening a RecordsetClone of the
subform's underlying recordsource and then looping through that and
going that way. Something like:

dim rs as dao.recordset
set rs = me!frmSub.RecordsetClone

do until rs.eof
'do your appending here
rs.movenext
loop

I imagine he means adding to the string to build up the body text of the
e-mail. Although 'appending' is often used specifically when talking about
inserting new records in a table, that's not what is meant here.
I just thought I'd add a comment because I've just answered a post on
MoveFirst, which I believe you will need if you use the form's
RecordsetClone but which has not been used here.
There also seems to be a mistake with set rs = me!frmSub.RecordsetClone
which I believe should be set rs = me!frmSub.Form.RecordsetClone
here is an example of the technique:

Private Sub cmdList_Click()

On Error GoTo Err_Handler

Dim rst As DAO.Recordset
Dim strBody As String

strBody = "Dear Santa," & vbCrLf & _
"Here is my Christmas list: " & vbCrLf

Set rst = Me!sbfSub1.Form.RecordsetClone

If rst.RecordCount > 0 Then

rst.MoveFirst

While Not rst.EOF
strBody = strBody & rst!ThingWanted & vbTab & rst!QtyRequired &
vbCrLf
rst.MoveNext
Wend

End If

MsgBox strBody, vbInformation

Exit_Handler:

If Not rst Is Nothing Then
Set rst = Nothing
End If

Exit Sub

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub

HTH
Fletcher
Nov 12 '05 #6

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

Similar topics

2
by: Mark B | last post by:
I have a form with a subform (normal) that itself has a subform (datasheet). I can't get a delete command button to work with the following code. It says "delete not available now". Any...
2
by: William Wisnieski | last post by:
Hello Everyone, Access 2000 I have a main form with a continuous subform. On the main form I have a text box that references a field on the subform. What I'd like it to do is show the value...
3
by: shumaker | last post by:
This code from the subform works for getting the value of a field of the main form named "WorkSheet": MsgBox Form_WorkSheet.Recordset.Fields("Clerk").Value Each record in the mainform datasheet...
4
by: mplogue | last post by:
I have a form (frmMain) with a subform (frmSub), each with enumerated fields of the same name (txt1, txt2, etc). I'm trying to make a function that will take the values for each field in frmMain,...
2
by: Axel | last post by:
Hi, a question about something that seems very simple at first glance: is it possible to reference other controls of a subform in a query window without referencing through the parent form? I...
6
by: Mat | last post by:
Dear all, What I want to do is be able to use a string to refer to a control on a subform. IE: Forms!("Form1!form2!controlA").name or
9
by: Alan | last post by:
Hmmm, I'm not too good with the syntax of referencing a subreport. I have frmInvoice which has the invoice details (e.g. ProductCode, ProductCost etc) in the subform frmInvoiceDetails. I'm trying...
21
by: cmd | last post by:
I have code in the OnExit event of a control on a subform. The code works properly in this instance. If, however, I put the same code in the OnExit event of a control on a Tab Control of a main...
3
by: ManningFan | last post by:
Here's a fun one, mein froinds! I have a form. The form (call it MainForm) has a subform control (call it SubForm). The actual subform that SubForm displays can change based on choices made on...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.