Conditionally Format/Hide Word Table Rows?

B

Beanz

Hi,

I have a word table that is populated from a SQL dataset. Is it
possible to format the text in a cell based on a field value in the
dataset and also hide/delete an entire table row based on the same
value?

For example, the field is called "Confiedntial". If this field is true
then certain text needs to be highlighted red and certain rows
hidden/deleted.

Can anyone offer any suggestions on how to achieve this?
 
P

Perry

Sure can.

SQL dataset?
Do you mean recordset? Pls confirm

Anyhow:
here's come sample code deleting an entire row in the first table in
ActiveDocument
when condition first field in records of *recordset* starting with a "b"

Krgrds,
Perry

Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim tbl As Word.Table, oRow As Word.Row
Dim rCnt As Integer
Set tbl = ActiveDocument.Tables(1)

rCnt = 1
Set oRow = tbl.Rows(1)
cn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Documents and Settings\Perry\Bureaublad\db\db.mdb;" & _
"User Id=admin;Password=;"
cn.Open
rs.Open "select * from table1", cn, adOpenStatic, adLockReadOnly


Do Until rs.EOF
If Left(rs(0), 1) = "b" Then
tbl.Rows(rCnt).Delete
End If
rs.MoveNext
Loop
rs.Close
cn.Close
Set cn = Nothing
 
P

Perry

Do Until rs.EOF
If Left(rs(0), 1) = "b" Then
tbl.Rows(rCnt).Delete
End If
rs.MoveNext
Loop

Forgot to increment the rowcounter
above shud read:

Do Until rs.EOF
If Left(rs(0), 1) = "b" Then
tbl.Rows(rCnt).Delete
End If
rs.MoveNext
rCnt = rCnt + 1
Loop
 
B

Beanz

I meant dataset as in ADO.Net dataset but it's effectivly the same
thing.

Thanks for the code.
 
P

Perry

I meant dataset as in ADO.Net dataset but it's effectivly the same
Just wanted to be sure here; people are using datasets (maybe) unknowingly
that it concerns a real object in ADO.net

But I presume yr problem is solved?
If not, repost.

Krgrds,
Perry
 

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