473,508 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Change Font in VBA

I included my VBA below. I would like to change the font of the
"strBody" to be Bold, italic, color, etc. The code that I attempted to
write is identified by ***. Any help would be appreciated.
------------------------------------------------
Private Sub EmlAll_Click()

On Error GoTo Err_EmlAll_Click
Dim strBody As String
Dim rs As Object
Dim con As Object
Dim DateEnter As Date
Dim NoMeetings As Integer
Dim Meeting(100) As Integer
Dim i As Integer
Dim j As Integer
Dim Room As String

***Dim fontheader As StdFont
***Dim bold As Boolean
***Dim name As String
***fontheader.bold = True
***fontheader.name = "Arial"

i = 0
j = 0
If Not IsNull(Me![DateEnter]) Then

'this is an sql string to search by date. You'll need to change the name
to fit your database.
sqlst = "Select Distinct MeetingID " _
& "From MeetingData " _
& "WHERE ((MeetingData.MeetingDate) = #" & Me![DateEnter] & "#)"

Set con = Application.CurrentProject.Connection
Set rs = CreateObject("ADODB.recordset")

rs.Open sqlst, con, 1

If Not rs.EOF Then

While Not rs.EOF

Meeting(i) = rs![MeetingID]
i = i + 1
rs.MoveNext
Wend

Else
MsgBox ("No meetings on this date") 'this is your msgbox for the
user to enter the date.
Exit Sub
End If
rs.Close

***Set fontheader.font = strBody

strBody = "Port Assignments: " & Format(Me![DateEnter], "Long Date") &
vbCr
For j = 0 To i

'the following is a sql string that you will need to edit according to
your needs. Enter sql string
'after the sqlst=. There was a problem with carriage returns so leave
undercores in after each line along with ampersands

sqlst = "SELECT MeetingData.MeetingTitle, MeetingData.MeetingDate, " _
& "MeetingData.Description, MeetingData.SetupTime, " _
& "MeetingData.StartTime,MeetingData.EndTime, [Usage].TimeID, " _
& "[Usage].Port,[Usage].DialUpNo " _
& "FROM MeetingData Left JOIN [Usage] ON " _
& "MeetingData.MeetingID=[Usage].MeetingID " _
& "WHERE ((MeetingData.MeetingID) = " & Meeting(j) & ")"

'Set con = Application.CurrentProject.Connection
'Set rs = CreateObject("ADODB.recordset")

rs.Open sqlst, con, 1

If Not rs.EOF Then

strBody = strBody & vbCr
strBody = strBody &
"-------------------------------------------------------------" & vbCr
strBody = strBody & "Subject: " & rs![MeetingTitle] & vbCr
strBody = strBody &
"-------------------------------------------------------------" & vbCr
strBody = strBody & "Setup Time: " & vbTab & Format(TimeSerial(3, 0,
0) + rs![SetupTime], "Short Time") & " E " & Format(TimeSerial(2, 0, 0)
+ rs![SetupTime], "Short Time") & " C " & Format(TimeSerial(1, 0, 0) +
rs![SetupTime], "Short Time") & " M " & Format(rs![SetupTime], "Short
Time") & " P " & vbCr
strBody = strBody & "Start Time: " & vbTab & Format(TimeSerial(3, 0,
0) + rs![StartTime], "Short Time") & " E " & Format(TimeSerial(2, 0, 0)
+ rs![StartTime], "Short Time") & " C " & Format(TimeSerial(1, 0, 0) +
rs![StartTime], "Short Time") & " M " & Format(rs![StartTime], "Short
Time") & " P " & vbCr
strBody = strBody & "End Time: " & vbTab & Format(TimeSerial(3, 0,
0) + rs![EndTime], "Short Time") & " E " & Format(TimeSerial(2, 0, 0) +
rs![EndTime], "Short Time") & " C " & Format(TimeSerial(1, 0, 0) +
rs![EndTime], "Short Time") & " M " & Format(rs![EndTime], "Short
Time") & " P " & vbCr
strBody = strBody & "Description:" & rs![Description] & vbCr & vbCr
strBody = strBody & "Participants" & vbTab & "Port Number" & vbTab &
"Dial Number" & vbCr
While Not rs.EOF
If IsNull(rs![TimeID]) Then
Room = ""
Else
Room = DLookup("RoomName", "TimeCard", "[TimeID] = " &
rs![TimeID])
End If

strBody = strBody & Room & vbTab & vbTab & rs![PortID] & vbTab &
rs![DialUpNo] & vbCr
rs.MoveNext
Wend
strBody = strBody & vbCr & "" & vbCr

End If
rs.Close

Next j

'================================================= ======================
=====================================
'You can edit the myItem.Subject,.To, &.Cc within the quotations. The
myItem.Body refers to the strBody string above
'DO NOT delete the strBody. In the myItem.To, you can input actual
email addresses seperated by a semicolin or exchange name

'================================================= ======================
=====================================
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.createitem(0)
myItem.Subject = "Port Assignments" 'enter your email subject line
here
myItem.Body = strBody
myItem.To = "" 'enter your destination email here
myItem.Cc = ""
myItem.display

Set rs = Nothing

Else
MsgBox ("Please enter a date") 'this is your error msgbox if no date is
entered. you can change this message if you'd like
End If
Exit_EmlAll_Click:
Exit Sub

Err_EmlAll_Click:
MsgBox Err.Description
Resume Exit_EmlAll_Click

End Sub
-------------------------------------------------------
Forgive me...I'm a beginner programmer with expert expectations.

*** Sent via Developersdex http://www.developersdex.com ***
Jul 10 '06 #1
1 11565
Tee GEE wrote:
I included my VBA below. I would like to change the font of the
"strBody" to be Bold, italic, color, etc. The code that I attempted to
write is identified by ***. Any help would be appreciated.
I think you need something additional to the current features in Access.
You might want to check out http://www.lebans.com/richtext.htm. Also,
check out any other offering Stephen may have regarding RTF via his
search field.

SendObject allows you to send an Email formatted RTF...but it appears
that in your case you need to get the body of the message into RTF
format first.
------------------------------------------------
Private Sub EmlAll_Click()

On Error GoTo Err_EmlAll_Click
Dim strBody As String
Dim rs As Object
Dim con As Object
Dim DateEnter As Date
Dim NoMeetings As Integer
Dim Meeting(100) As Integer
Dim i As Integer
Dim j As Integer
Dim Room As String

***Dim fontheader As StdFont
***Dim bold As Boolean
***Dim name As String
***fontheader.bold = True
***fontheader.name = "Arial"

i = 0
j = 0
If Not IsNull(Me![DateEnter]) Then

'this is an sql string to search by date. You'll need to change the name
to fit your database.
sqlst = "Select Distinct MeetingID " _
& "From MeetingData " _
& "WHERE ((MeetingData.MeetingDate) = #" & Me![DateEnter] & "#)"

Set con = Application.CurrentProject.Connection
Set rs = CreateObject("ADODB.recordset")

rs.Open sqlst, con, 1

If Not rs.EOF Then

While Not rs.EOF

Meeting(i) = rs![MeetingID]
i = i + 1
rs.MoveNext
Wend

Else
MsgBox ("No meetings on this date") 'this is your msgbox for the
user to enter the date.
Exit Sub
End If
rs.Close

***Set fontheader.font = strBody

strBody = "Port Assignments: " & Format(Me![DateEnter], "Long Date") &
vbCr
For j = 0 To i

'the following is a sql string that you will need to edit according to
your needs. Enter sql string
'after the sqlst=. There was a problem with carriage returns so leave
undercores in after each line along with ampersands

sqlst = "SELECT MeetingData.MeetingTitle, MeetingData.MeetingDate, " _
& "MeetingData.Description, MeetingData.SetupTime, " _
& "MeetingData.StartTime,MeetingData.EndTime, [Usage].TimeID, " _
& "[Usage].Port,[Usage].DialUpNo " _
& "FROM MeetingData Left JOIN [Usage] ON " _
& "MeetingData.MeetingID=[Usage].MeetingID " _
& "WHERE ((MeetingData.MeetingID) = " & Meeting(j) & ")"

'Set con = Application.CurrentProject.Connection
'Set rs = CreateObject("ADODB.recordset")

rs.Open sqlst, con, 1

If Not rs.EOF Then

strBody = strBody & vbCr
strBody = strBody &
"-------------------------------------------------------------" & vbCr
strBody = strBody & "Subject: " & rs![MeetingTitle] & vbCr
strBody = strBody &
"-------------------------------------------------------------" & vbCr
strBody = strBody & "Setup Time: " & vbTab & Format(TimeSerial(3, 0,
0) + rs![SetupTime], "Short Time") & " E " & Format(TimeSerial(2, 0, 0)
+ rs![SetupTime], "Short Time") & " C " & Format(TimeSerial(1, 0, 0) +
rs![SetupTime], "Short Time") & " M " & Format(rs![SetupTime], "Short
Time") & " P " & vbCr
strBody = strBody & "Start Time: " & vbTab & Format(TimeSerial(3, 0,
0) + rs![StartTime], "Short Time") & " E " & Format(TimeSerial(2, 0, 0)
+ rs![StartTime], "Short Time") & " C " & Format(TimeSerial(1, 0, 0) +
rs![StartTime], "Short Time") & " M " & Format(rs![StartTime], "Short
Time") & " P " & vbCr
strBody = strBody & "End Time: " & vbTab & Format(TimeSerial(3, 0,
0) + rs![EndTime], "Short Time") & " E " & Format(TimeSerial(2, 0, 0) +
rs![EndTime], "Short Time") & " C " & Format(TimeSerial(1, 0, 0) +
rs![EndTime], "Short Time") & " M " & Format(rs![EndTime], "Short
Time") & " P " & vbCr
strBody = strBody & "Description:" & rs![Description] & vbCr & vbCr
strBody = strBody & "Participants" & vbTab & "Port Number" & vbTab &
"Dial Number" & vbCr
While Not rs.EOF
If IsNull(rs![TimeID]) Then
Room = ""
Else
Room = DLookup("RoomName", "TimeCard", "[TimeID] = " &
rs![TimeID])
End If

strBody = strBody & Room & vbTab & vbTab & rs![PortID] & vbTab &
rs![DialUpNo] & vbCr
rs.MoveNext
Wend
strBody = strBody & vbCr & "" & vbCr

End If
rs.Close

Next j

'================================================= ======================
=====================================
'You can edit the myItem.Subject,.To, &.Cc within the quotations. The
myItem.Body refers to the strBody string above
'DO NOT delete the strBody. In the myItem.To, you can input actual
email addresses seperated by a semicolin or exchange name

'================================================= ======================
=====================================
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.createitem(0)
myItem.Subject = "Port Assignments" 'enter your email subject line
here
myItem.Body = strBody
myItem.To = "" 'enter your destination email here
myItem.Cc = ""
myItem.display

Set rs = Nothing

Else
MsgBox ("Please enter a date") 'this is your error msgbox if no date is
entered. you can change this message if you'd like
End If
Exit_EmlAll_Click:
Exit Sub

Err_EmlAll_Click:
MsgBox Err.Description
Resume Exit_EmlAll_Click

End Sub
-------------------------------------------------------
Forgive me...I'm a beginner programmer with expert expectations.

*** Sent via Developersdex http://www.developersdex.com ***
Jul 11 '06 #2

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

Similar topics

8
9423
by: S.W. Rasmussen | last post by:
A trivial (?) question: does anyone know how to change the shape of the cursor in a RichTextBox control from the normal vertical line to an underscore?
3
13205
by: BKM | last post by:
Is there a way that I can change the default font in VB6 so I don't have to constantly change the font of each new control that I add to my project?
16
14502
by: Coder Droid | last post by:
I'm trying my first table-less site, and I've bumped my head up against a wall. I can't change the font size within a div. Real quick, my style sheet has: -------------------------------------...
9
3754
by: Dr John Stockton | last post by:
Assuming default set-ups and considering all reasonable browsers, whatever that may mean, what should an author expect that his readers in general will see (with visual browsers) for a page with...
3
379
by: (Pete Cresswell) | last post by:
I'd like to have SQL come up in a mono-spaced font like Courier New. Anybody been able to do this? -- PeteCresswell
2
8740
by: Hariharan S | last post by:
Hi Guys, Have an issue with the Font object. I have a text box in which I can enter text and I have included a small button which upon selection, should enable me to change the newly entered...
2
16173
by: Jim | last post by:
Working with VB.net under VS.Net 2003. Have a simple form with a Button1. I want to change the font on the button when the button is clicked. Is there a way to Dynamically change the Font for...
3
5608
by: Phil Stanton | last post by:
Correct me if I'm wrong, but is it impossible to change the font in a report field when in print preview (MDE database) or can it only be done in design view in the MDB database. Part of my...
5
3048
by: _Who | last post by:
I spent all day yesterday trying different things. Something has happened so I can't change font size. I have a table and in the first cell I have only text. I tried using the cell's Style...
18
7727
by: wizdom | last post by:
Help - change text on click - text has another onclick inside with php variables ---------- I think what I'm trying to do is simple. I have a 2 buttons on a page. 1 button allows a thread of...
0
7233
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
7342
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
7410
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...
1
7067
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
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...
1
5060
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...
0
3215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3201
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.