From: pkeegs on
I have set up a word template to include a combobox as per the instructions
on the article at http://support.microsoft.com/?kbid=306258. Below is the
code I have entered per the article with my own database ("FriendsPlus") and
source field ("CarePlan") entered. The macro does not seem to recognise the
first two Dim statements ("User defined types not defined"). What needs to be
done to make the macro function.

I would also like to activate the Macro wherever I place the cursor rather
than in a Field. What changes would I need in the macro to achieve that?

Option Explicit

Private Sub UserForm_Initialize()

Dim dbDatabase As Database
Dim rsFriendsPlus As Recordset
Dim i As Integer
Dim aResults()

' This code activates the Database connection.Change
' the path to reflect your database.
Set dbDatabase = OpenDatabase("E:\Friends Plus\FriendsPlus.mdb")

' This code opens the Customers table. Change the Table
' to reflect the desired table.
Set rsFriendsPlus = dbDatabase.OpenRecordset("CarePlan", dbOpenSnapshot)

i = 0

With rsFriendsPlus
' This code populates the combo box with the values
' in the CompanyName Field.

Do Until .EOF
ComboBox1.Colum(0, i) = .Fields("CarePlan")
.MoveNext
i = i + 1
Loop

End With

End Sub

Private Sub ComboBox1_Change()

ActiveDocument.FormFields("Text1").Result = ComboBox1.Value

End Sub

Private Sub Cmdclose_Click()

End

End Sub


Regards
From: pkeegs on
Hi again - I meant to say that in placing the cursor in the document I would
like to activate the Form with a keystroke (ctrl+c)so that a user can select
from the list.

Regards again.

"pkeegs" wrote:

> I have set up a word template to include a combobox as per the instructions
> on the article at http://support.microsoft.com/?kbid=306258. Below is the
> code I have entered per the article with my own database ("FriendsPlus") and
> source field ("CarePlan") entered. The macro does not seem to recognise the
> first two Dim statements ("User defined types not defined"). What needs to be
> done to make the macro function.
>
> I would also like to activate the Macro wherever I place the cursor rather
> than in a Field. What changes would I need in the macro to achieve that?
>
> Option Explicit
>
> Private Sub UserForm_Initialize()
>
> Dim dbDatabase As Database
> Dim rsFriendsPlus As Recordset
> Dim i As Integer
> Dim aResults()
>
> ' This code activates the Database connection.Change
> ' the path to reflect your database.
> Set dbDatabase = OpenDatabase("E:\Friends Plus\FriendsPlus.mdb")
>
> ' This code opens the Customers table. Change the Table
> ' to reflect the desired table.
> Set rsFriendsPlus = dbDatabase.OpenRecordset("CarePlan", dbOpenSnapshot)
>
> i = 0
>
> With rsFriendsPlus
> ' This code populates the combo box with the values
> ' in the CompanyName Field.
>
> Do Until .EOF
> ComboBox1.Colum(0, i) = .Fields("CarePlan")
> .MoveNext
> i = i + 1
> Loop
>
> End With
>
> End Sub
>
> Private Sub ComboBox1_Change()
>
> ActiveDocument.FormFields("Text1").Result = ComboBox1.Value
>
> End Sub
>
> Private Sub Cmdclose_Click()
>
> End
>
> End Sub
>
>
> Regards
From: pkeegs on
I have solved part of my problem. I had clicked on the Reference "Microsoft
DAO 3.6 Object Library" but had failed to tick it. Ensuring the tick was
there solved the problem of the Dim statements. I would however like to be
able to activate the ComboBox with a keystroke at the cursor point in the
Word text if anyone can help.

"pkeegs" wrote:

> I have set up a word template to include a combobox as per the instructions
> on the article at http://support.microsoft.com/?kbid=306258. Below is the
> code I have entered per the article with my own database ("FriendsPlus") and
> source field ("CarePlan") entered. The macro does not seem to recognise the
> first two Dim statements ("User defined types not defined"). What needs to be
> done to make the macro function.
>
> I would also like to activate the Macro wherever I place the cursor rather
> than in a Field. What changes would I need in the macro to achieve that?
>
> Option Explicit
>
> Private Sub UserForm_Initialize()
>
> Dim dbDatabase As Database
> Dim rsFriendsPlus As Recordset
> Dim i As Integer
> Dim aResults()
>
> ' This code activates the Database connection.Change
> ' the path to reflect your database.
> Set dbDatabase = OpenDatabase("E:\Friends Plus\FriendsPlus.mdb")
>
> ' This code opens the Customers table. Change the Table
> ' to reflect the desired table.
> Set rsFriendsPlus = dbDatabase.OpenRecordset("CarePlan", dbOpenSnapshot)
>
> i = 0
>
> With rsFriendsPlus
> ' This code populates the combo box with the values
> ' in the CompanyName Field.
>
> Do Until .EOF
> ComboBox1.Colum(0, i) = .Fields("CarePlan")
> .MoveNext
> i = i + 1
> Loop
>
> End With
>
> End Sub
>
> Private Sub ComboBox1_Change()
>
> ActiveDocument.FormFields("Text1").Result = ComboBox1.Value
>
> End Sub
>
> Private Sub Cmdclose_Click()
>
> End
>
> End Sub
>
>
> Regards
From: Jay Freedman on
In the article you worked from, the macro gocombobox() that displays
the userform is set as the entry macro for a form field. But you can
launch that macro (or any macro) in several different ways. One of
them is to assign a keyboard shortcut.

If you have Word 2003 or earlier, the process is at
http://www.word.mvps.org/FAQs/Customization/AsgnCmdOrMacroToHotkey.htm.
If it's Word 2007, go to Office button > Word Options > Customize and
click the Keyboard Customize button and then follow the same procedure
from step 2.

The code you have will put the answer into the Text1 form field
regardless of where the cursor is when you launch the macro. If that's
not what you want, please explain further.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Thu, 29 Oct 2009 17:04:01 -0700, pkeegs
<pkeegs(a)discussions.microsoft.com> wrote:

>I have solved part of my problem. I had clicked on the Reference "Microsoft
>DAO 3.6 Object Library" but had failed to tick it. Ensuring the tick was
>there solved the problem of the Dim statements. I would however like to be
>able to activate the ComboBox with a keystroke at the cursor point in the
>Word text if anyone can help.
>
>"pkeegs" wrote:
>
>> I have set up a word template to include a combobox as per the instructions
>> on the article at http://support.microsoft.com/?kbid=306258. Below is the
>> code I have entered per the article with my own database ("FriendsPlus") and
>> source field ("CarePlan") entered. The macro does not seem to recognise the
>> first two Dim statements ("User defined types not defined"). What needs to be
>> done to make the macro function.
>>
>> I would also like to activate the Macro wherever I place the cursor rather
>> than in a Field. What changes would I need in the macro to achieve that?
>>
>> Option Explicit
>>
>> Private Sub UserForm_Initialize()
>>
>> Dim dbDatabase As Database
>> Dim rsFriendsPlus As Recordset
>> Dim i As Integer
>> Dim aResults()
>>
>> ' This code activates the Database connection.Change
>> ' the path to reflect your database.
>> Set dbDatabase = OpenDatabase("E:\Friends Plus\FriendsPlus.mdb")
>>
>> ' This code opens the Customers table. Change the Table
>> ' to reflect the desired table.
>> Set rsFriendsPlus = dbDatabase.OpenRecordset("CarePlan", dbOpenSnapshot)
>>
>> i = 0
>>
>> With rsFriendsPlus
>> ' This code populates the combo box with the values
>> ' in the CompanyName Field.
>>
>> Do Until .EOF
>> ComboBox1.Colum(0, i) = .Fields("CarePlan")
>> .MoveNext
>> i = i + 1
>> Loop
>>
>> End With
>>
>> End Sub
>>
>> Private Sub ComboBox1_Change()
>>
>> ActiveDocument.FormFields("Text1").Result = ComboBox1.Value
>>
>> End Sub
>>
>> Private Sub Cmdclose_Click()
>>
>> End
>>
>> End Sub
>>
>>
>> Regards
From: pkeegs on
Thanks for the reply Jay - What I want to do is create a small list in a form
from a larger list (the combobox source). I would like to place the cursor at
the start of a line, use a keyboard shortcut to launch the macro and select
from the combobox form and then move the cursor to the next line and repeat.
I realised after I had started working with the form field option that I
would have to have a separate field & macro for each selection. I am sure
that I can do it the other way. The source list in the database has more than
30 items and will be added to/modified over time. I am comfortable with
assigning a hotkey to the macro and am very familiar with forms and VBA in
Excel, but Word seems to have quite a different protocol and language.

Regards

"Jay Freedman" wrote:

> In the article you worked from, the macro gocombobox() that displays
> the userform is set as the entry macro for a form field. But you can
> launch that macro (or any macro) in several different ways. One of
> them is to assign a keyboard shortcut.
>
> If you have Word 2003 or earlier, the process is at
> http://www.word.mvps.org/FAQs/Customization/AsgnCmdOrMacroToHotkey.htm.
> If it's Word 2007, go to Office button > Word Options > Customize and
> click the Keyboard Customize button and then follow the same procedure
> from step 2.
>
> The code you have will put the answer into the Text1 form field
> regardless of where the cursor is when you launch the macro. If that's
> not what you want, please explain further.
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the
> newsgroup so all may benefit.
>
> On Thu, 29 Oct 2009 17:04:01 -0700, pkeegs
> <pkeegs(a)discussions.microsoft.com> wrote:
>
> >I have solved part of my problem. I had clicked on the Reference "Microsoft
> >DAO 3.6 Object Library" but had failed to tick it. Ensuring the tick was
> >there solved the problem of the Dim statements. I would however like to be
> >able to activate the ComboBox with a keystroke at the cursor point in the
> >Word text if anyone can help.
> >
> >"pkeegs" wrote:
> >
> >> I have set up a word template to include a combobox as per the instructions
> >> on the article at http://support.microsoft.com/?kbid=306258. Below is the
> >> code I have entered per the article with my own database ("FriendsPlus") and
> >> source field ("CarePlan") entered. The macro does not seem to recognise the
> >> first two Dim statements ("User defined types not defined"). What needs to be
> >> done to make the macro function.
> >>
> >> I would also like to activate the Macro wherever I place the cursor rather
> >> than in a Field. What changes would I need in the macro to achieve that?
> >>
> >> Option Explicit
> >>
> >> Private Sub UserForm_Initialize()
> >>
> >> Dim dbDatabase As Database
> >> Dim rsFriendsPlus As Recordset
> >> Dim i As Integer
> >> Dim aResults()
> >>
> >> ' This code activates the Database connection.Change
> >> ' the path to reflect your database.
> >> Set dbDatabase = OpenDatabase("E:\Friends Plus\FriendsPlus.mdb")
> >>
> >> ' This code opens the Customers table. Change the Table
> >> ' to reflect the desired table.
> >> Set rsFriendsPlus = dbDatabase.OpenRecordset("CarePlan", dbOpenSnapshot)
> >>
> >> i = 0
> >>
> >> With rsFriendsPlus
> >> ' This code populates the combo box with the values
> >> ' in the CompanyName Field.
> >>
> >> Do Until .EOF
> >> ComboBox1.Colum(0, i) = .Fields("CarePlan")
> >> .MoveNext
> >> i = i + 1
> >> Loop
> >>
> >> End With
> >>
> >> End Sub
> >>
> >> Private Sub ComboBox1_Change()
> >>
> >> ActiveDocument.FormFields("Text1").Result = ComboBox1.Value
> >>
> >> End Sub
> >>
> >> Private Sub Cmdclose_Click()
> >>
> >> End
> >>
> >> End Sub
> >>
> >>
> >> Regards
> .
>