open custom form

C

cinnamngrl

I created a custom form to record information (school attendance) and
convert that information to a journal note for a contact. What I
can't figure out is how/where to put a button or a menu item in
Outlook so I can access the info easily. the only way I can do it now
is to open VB editor, go to form, View code, run code. This form is
set up to repeat itself because it takes so long to open the form I
try to do the data entry in batches. This is not a customized
outlook form, it is just a small pop up box with five text boxes.

I created a button on contact form that creates an email with the
contact in the subject line.

Sub CommandButton1_Click()
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olMailItem)
myItem.Subject= Item.Fullname & " " & Item.User1
myItem.Display
End Sub

But this new form will search for the correct contact, and I want to
put the button in the tool bar.






VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} school
Caption = "UserForm1"
ClientHeight = 3675
ClientLeft = 45
ClientTop = 330
ClientWidth = 3825
OleObjectBlob = "school.frx":0000
StartUpPosition = 1 'CenterOwner
End
Attribute VB_Name = "school"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Function item_open()


End Function
Private Sub CommandButton1_Click()
school.Hide
lname = TextBox1.Text
mydate = TextBox2.Text
absent = TextBox3.Text
tardy = TextBox4.Text
present = TextBox5.Text
TextBox1.EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection
TextBox2.EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection
TextBox3.EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection
TextBox4.EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection
TextBox5.EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection
TextBox2.Value = mydate


school.Hide

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set allcontacts =
myNameSpace.GetDefaultFolder(olFolderContacts).Items
Set mycontacts = allcontacts.Restrict("[Categories]="" caseload""")

line1:
If lname = "" Then
finame = "unknown"
GoTo lineq
End If

Set myItems = mycontacts.Restrict("[LastName] = " & lname & "")
linet:

Dim who(1 To 10, 1 To 4)
For Each Itm In myItems
x = x + 1
who(x, 1) = Itm.FullName
who(x, 2) = Itm.User1
who(x, 3) = Itm.CompanyName
who(x, 4) = Itm.HomeAddress
Next

If x = 0 And notfound < 1 Then
finame = InputBox("What is first name?")
Set myItems = mycontacts.Restrict("[FirstName] = "" & finame & """)
notfound = notfound + 1

GoTo linet
End If
If notfound > 1 Then GoTo lineu
lineu:
lineq:
If x <> 0 Then
Set inq = Assistant.NewBalloon

With inq
.Heading = "Available in Contacts"
.Text = "Select one"
For i = 1 To x
.Labels(i).Text = who(i, 1) & " " & who(i, 2)
Next
.Button = msoButtonSetOK
Debug.Print where
End With
Select Case inq.Show
Case 1
fname = who(1, 1)
Case 2
fname = who(2, 1)
Case 3
fname = who(3, 1)
Case 4
fname = who(4, 1)
Case 5
fname = who(5, 1)
Case Else
notfound = notfound + 1
GoTo lineu
End Select
End If
If x = 0 Then
MsgBox ("Can't find this kid")
GoTo linend
End If

Debug.Print fname
Set myjournal = myOlApp.CreateItem(olJournalItem)


For Each Itm In myItems
If Itm.FullName = fname Then

myjournal.Subject = Itm.FullName
myjournal.Links.Add Itm
myjournal.Type = "Note"
fulldate = mydate & " 12:00:00 PM"
Debug.Print fulldate
myjournal.Start = fulldate
Debug.Print myjournal.Start

myschool = InputBox("Boston Public School Attendance as of " &
mydate & Chr(13) & "Absent: " & absent & Chr(13) & "Tardy: " & tardy
& Chr(13) & "from which school?", "check facts", Itm.CompanyName)
myjournal.Body = myschool & " Attendance as of " & mydate & Chr(13) &
"Absent: " & absent & Chr(13) & "Tardy: " & tardy & Chr(13) &
"Present: " & present
myjournal.Save
End If
Itm.CompanyName = myschool
Itm.Save
Next
TextBox1.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
TextBox5.Value = ""
TextBox2.Value = mydate
linend:
school.Show

End Sub
Private Sub UserForm_Click()
school.Hide

End Sub
 
S

Sue Mosher [MVP-Outlook]

So you're talking about a VBA user form (the topic of the
microsoft.public.outlook.program_vba newsgroup), not an Outlook custom form
(the topic of this newsgroup)? And you're asking how to display that user
form?
To do that, you can write a macro that instantiates and shows it:

Sub ShowMyUserForm()
Set mySchool = New school
school.Show
End Sub

You can customize any toolbar or the QAT in Outlook 2007 to add a button for
any macro.


--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54




cinnamngrl said:
I created a custom form to record information (school attendance) and
convert that information to a journal note for a contact. What I
can't figure out is how/where to put a button or a menu item in
Outlook so I can access the info easily. the only way I can do it now
is to open VB editor, go to form, View code, run code. This form is
set up to repeat itself because it takes so long to open the form I
try to do the data entry in batches. This is not a customized
outlook form, it is just a small pop up box with five text boxes.

I created a button on contact form that creates an email with the
contact in the subject line.

Sub CommandButton1_Click()
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olMailItem)
myItem.Subject= Item.Fullname & " " & Item.User1
myItem.Display
End Sub

But this new form will search for the correct contact, and I want to
put the button in the tool bar.






VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} school
Caption = "UserForm1"
ClientHeight = 3675
ClientLeft = 45
ClientTop = 330
ClientWidth = 3825
OleObjectBlob = "school.frx":0000
StartUpPosition = 1 'CenterOwner
End
Attribute VB_Name = "school"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Function item_open()


End Function
Private Sub CommandButton1_Click()
school.Hide
lname = TextBox1.Text
mydate = TextBox2.Text
absent = TextBox3.Text
tardy = TextBox4.Text
present = TextBox5.Text
TextBox1.EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection
TextBox2.EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection
TextBox3.EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection
TextBox4.EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection
TextBox5.EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection
TextBox2.Value = mydate


school.Hide

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set allcontacts =
myNameSpace.GetDefaultFolder(olFolderContacts).Items
Set mycontacts = allcontacts.Restrict("[Categories]="" caseload""")

line1:
If lname = "" Then
finame = "unknown"
GoTo lineq
End If

Set myItems = mycontacts.Restrict("[LastName] = " & lname & "")
linet:

Dim who(1 To 10, 1 To 4)
For Each Itm In myItems
x = x + 1
who(x, 1) = Itm.FullName
who(x, 2) = Itm.User1
who(x, 3) = Itm.CompanyName
who(x, 4) = Itm.HomeAddress
Next

If x = 0 And notfound < 1 Then
finame = InputBox("What is first name?")
Set myItems = mycontacts.Restrict("[FirstName] = "" & finame & """)
notfound = notfound + 1

GoTo linet
End If
If notfound > 1 Then GoTo lineu
lineu:
lineq:
If x <> 0 Then
Set inq = Assistant.NewBalloon

With inq
.Heading = "Available in Contacts"
.Text = "Select one"
For i = 1 To x
.Labels(i).Text = who(i, 1) & " " & who(i, 2)
Next
.Button = msoButtonSetOK
Debug.Print where
End With
Select Case inq.Show
Case 1
fname = who(1, 1)
Case 2
fname = who(2, 1)
Case 3
fname = who(3, 1)
Case 4
fname = who(4, 1)
Case 5
fname = who(5, 1)
Case Else
notfound = notfound + 1
GoTo lineu
End Select
End If
If x = 0 Then
MsgBox ("Can't find this kid")
GoTo linend
End If

Debug.Print fname
Set myjournal = myOlApp.CreateItem(olJournalItem)


For Each Itm In myItems
If Itm.FullName = fname Then

myjournal.Subject = Itm.FullName
myjournal.Links.Add Itm
myjournal.Type = "Note"
fulldate = mydate & " 12:00:00 PM"
Debug.Print fulldate
myjournal.Start = fulldate
Debug.Print myjournal.Start

myschool = InputBox("Boston Public School Attendance as of " &
mydate & Chr(13) & "Absent: " & absent & Chr(13) & "Tardy: " & tardy
& Chr(13) & "from which school?", "check facts", Itm.CompanyName)
myjournal.Body = myschool & " Attendance as of " & mydate & Chr(13) &
"Absent: " & absent & Chr(13) & "Tardy: " & tardy & Chr(13) &
"Present: " & present
myjournal.Save
End If
Itm.CompanyName = myschool
Itm.Save
Next
TextBox1.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
TextBox5.Value = ""
TextBox2.Value = mydate
linend:
school.Show

End Sub
Private Sub UserForm_Click()
school.Hide

End Sub
 
C

cinnamngrl

So you're talking about a VBA user form (the topic of the
microsoft.public.outlook.program_vba newsgroup), not an Outlook custom form
(the topic of this newsgroup)? And you're asking how to display that user
form?
To do that, you can write a macro that instantiates and shows it:

Sub ShowMyUserForm()
    Set mySchool = New school
    school.Show
End Sub

You can customize any toolbar or the QAT in Outlook 2007 to add a button for
any macro.

--
Sue Mosher, Outlook MVP
   Author of Microsoft Outlook 2007 Programming:
     Jumpstart for Power Users and Administrators
   http://www.outlookcode.com/article.aspx?id=54


Thank you. it works great. So this group is about customized the
message class for outlook item types (contact, tasks, etc), but not
"user forms". I 'm sure you can tell that I am stumbling aroung the
dim part of the cave.
 

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