Microsoft Grid

A

ablei2000

Hello:

I'm trying to populate a grid control Using VBscript
Set Controls = Item.GetInspector.ModifiedFormPages("Grid Test Page").Controls
Set ctrlGrid = Controls("DataGrid1")
ctrlGrid.Col = 1
ctrlGrid.Row = 1
ctrlGrid(1,1).value = "Field Value"

But line ctrlGrid.Col = 1 causes the "Rowset not available" error.
What's wrong here?

On another note the Outlook can't find the DataSource property when I'm trying to bind a grid
to ADO recordset:
ctrlGrid.DataSource = rs

Is that because the DataSource property is greyed out on the grid's property list?

Please advice. Where else if not here?
 
K

Ken Slovak - [MVP - Outlook]

You can't use a bound recordset in a grid control in an Outlook form.
You have to populate the grid directly from the recordset in your code
using something like AddItem depending on the grid you are using.
 
A

ablei2000

Thank very much, Ke

But I can't find the way to populate the grid even without direct binding.
The example I gave in my first email doesn't work. Coudl you give me an example

Thank you.
 
K

Ken Slovak - [MVP - Outlook]

Assuming you have something like an ADO recordset that has all the
data you want in the grid you would iterate that recordset and get
field data into a string with each field separated by a Tab character
and then use the AddItem method of the gird to add a new row.
Something like this:

Sub PopulateGrid(oGrid, oRecordSet)
Dim strRow

If oRecordSet.State = 1 Then 'open
oRecordSet.MoveFirst
Do While Not oRecordSet.EOF
strRow = oRecordSet.Fields("FirstField")
strRow = strRow & vbTab & oRecordSet.Fields("NextField")
'and so on adding fields
oGrid.AddItem strRow
oRecordSet.MoveNext
Loop
End If
End Sub
 
A

ablei2000

Great! Thanks Ken. That works for Microsoft FlexGrid.
Simple Microsoft grid does not have addItem method, and I do not see any replacement.
I'm not smart enough to use vbTab to populate each sell individually.

How can contribute to you MVP status to make it TMVP - The Most Valuable :)

P.S You also anwered on my question about COM add-in vs ActiveX.

Sorry to be enjoying but is there a way to call a VBA macro from Vbscript in Outlook?
 
K

Ken Slovak - [MVP - Outlook]

I'm not sure what grid you mean. The grids that are available in
Visual Studio or Office Developer would be the MS FlexGrid or the
HFlexGrid. If you mean some other grid it must have a method that
allows adding rows to it. You would have to use the Object Browser or
Help for that grid control to see what methods are available for your
use.

Using vbTab to separate columns in a row in the grid works for the 2
grid controls I mentioned. What would be used in another grid would
depend on the grid. It's not hard to get each field you are interested
in from the current record in a recordset and concatenate each field
separated by vbTab characters. It's just repetitive code in a loop.

You can call a VBA procedure from form code but it's not supported
officially and may not be doable in later versions of Outlook. See
http://support.microsoft.com/?kbid=221827 for information on how to
call a VBA procedure from VBScript in a form.
 

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