New to VBA - error 6 - overflow? explain please.

G

Guest

Private Sub cmdUpdate_Click()
Dim objApp As Application
Dim objNS As NameSpace
Dim objCalender As MAPIFolder
Dim objItem As AppointmentItem
Dim strSubject As String
Dim intMinutes As Integer

Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objCalendar = objNS.GetDefaultFolder(olFolderCalendar)

intMinutes = 24 * 60 * txtDays.Value '<<<<<<<< error
For Each objItem In objCalendar.Items
strSubject = objItem.Subject
If InStr(strSubject, "Birthday") > 0 Or _
InStr(strSubject, "Anniversary") > 0 Then
objItem.ReminderSet = True
objItem.ReminderMinutesBeforeStart = intMinutes
objItem.Save
End If
Next
Beep
End Sub
 
S

Sue Mosher [MVP-Outlook]

Before using the value from a text box on a form in a calculation, you
should check that it contains a numeric value.

If IsNumeric(txtDays.Value) Then
intMinutes = 24 * 60 * txtDays.Value
' other code follows here
End If
 
M

Michael Bauer

In addition to Sue: You probably should declare intMinutes as Long. In
VB(A) the upper bound of an Integer is 32.767.
 
G

Guest

What I find also is that a user entry of greater then 23 days will cause this
overflow error; whereas a user response of less then 23 day works fine.

"If IsNumeric(txtDays.Value) Then" did not fix the overflow error.

"Dim IntMinute as Long" as M Bauer suggested fixed the overflow error.

Thanks.
 
S

Sue Mosher [MVP-Outlook]

Yes, you need both.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top