Word Control Help Please

W

wandererxp

Hello,

I have a couple of documents that I would like to automate with the use
of Word Controls, macros and a standard template to be put it the word
startup folder. On the template document there are 4 controls:
TextBox1, TextBox2, TextBox4 and cboFrmNbr. When I run my macros form
within the Template everything works successfully. So I created 2
Toolbar buttons to run each macro. When open up one of the word
documents containing the same three controls (controls named the same)
I can't get the macros to run. I get an error message stating Error
Occured: Object Required. So my question is how to I read/write values
in textboxes and list boxes in a new document via a template that is
starting up when word starts up.

Any help would be greatly appreciated!!!!

Thanks in Advance,

-SK

Here is a snipet of what I'm trying to do:
Public Sub CommandButton1_Click()
Dim dte As String
Dim dte1 As String

On Error GoTo errHandle

'--Clearing the barcode values from the label object
clrLabel

dte = Format(Now, "mm/dd/yyyy")
dte1 = Format(Now - 1, "mm/dd/yyyy")
cboFrmNbr.Clear
TextBox1.Text = ""
'--Date control for displaying the DATE information
TextBox2.Text = dte

TextBox4.Text = dte1


'--Populating the combo box with form name values
sSentenceCnt = ActiveDocument.Sentences.Count

'--Populating the combo box
PopulateCombo

Exit Sub

errHandle:
MsgBox "Error Occured : " & Err.Description, vbOKOnly,
"Information"
Exit Sub
End Sub

Private Sub PopulateCombo()
Dim objCon As ADODB.Connection
Dim objCom As ADODB.Command
Dim objRS As ADODB.Recordset
Dim k As Integer

On Error GoTo errHandle

Set objCon = New ADODB.Connection
Set objCom = New ADODB.Command

'--Creating the DB connection string
'--Please change the below connection string as per your server and
database being used.
'--objCon.ConnectionString =
"PROVIDER=SQLOLEDB.1;PASSWORD=password;PERSIST SECURITY
INFO=TRUE;Initial Catalog='Northwind';USER ID=sa"
objCon.ConnectionString = "Driver={SQL
Server};Server=********;Trusted_Connection=no;Database=WAM;Uid=*****;Pwd=*****"

'--Opening the connection
objCon.Open objCon.ConnectionString

'--assigning the command object parameters
With objCom
.CommandText = "SELECT formnum from tblforms" 'Name of the
stored procedure
.ActiveConnection = objCon.ConnectionString
End With

'--Store the result in a recordset
Set objRS = objCom.Execute

objRS.MoveFirst
MsgBox "DB Connected " & objRS.RecordCount
'--Open the recordset
Do While Not objRS.EOF
For k = 0 To objRS.Fields.Count - 1
cboFrmNbr.AddItem objRS!formnum
Next
objRS.MoveNext
Loop

'--Close the recordset
objRS.Close

'--close connection
objCon.Close

'--cleaning up
Set objCom = Nothing
Set objCon = Nothing
Set objRS = Nothing

Exit Sub

errHandle:
MsgBox ("Error occured : " & Err.Description), vbOKOnly
End Sub
 
W

Word Heretic

G'day "wandererxp" <[email protected]>,

From VBA you can properly set the OnAction properties of the toolbar
controls so that they point to the global template, not the local.

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


wandererxp reckoned:
 

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