473,563 Members | 2,695 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MS Word - Adding FormFields dynamically through VBA - Help!

This is an interesting one...

You have a Word document with a parent table. Inside this is another
table. This subtable has 4 columns, where I need to dynamically
insert FormFields into each cell when I add a new row.

Problem. Using the function below the oFormField object only ever
points to the first of the newly inserted FormFields!?! The First
cell in the newly appended row ends up being named Text2_4 instead of
Text2_1.

Public Sub AddRow()
'unprotect file
ActiveDocument. Unprotect Password:=""

'get current number of Rows:
Dim iCount As Integer
Dim iCell As Integer

'Add row
ActiveDocument. Tables(1).Table s(1).Rows.Add
iCount = ActiveDocument. Tables(1).Table s(1).Rows.Count
Dim oFormfield As FormField
Dim sName As String
Dim sText As String
Dim oRange As Range

For iCell = 1 To 4
sName = "Text" & iCount & "_" & iCell
sText = ""
Set oRange =
ActiveDocument. Tables(1).Table s(1).Rows(iCoun t).Cells(iCell) .Range
Set oFormfield = ActiveDocument. FormFields.Add( Range:=oRange,
Type:=wdFieldFo rmTextInput)
With oFormfield
.TextInput.Defa ult = sText
.Name = sName
'Each cell has different formatting - this is simplified.
End With

Set oFormfield = Nothing
Set oRange = Nothing
Next

'Set Cursor
Application.OnT ime When:=Now + TimeValue("00:0 0:01"),
Name:="SetFormF ieldFocus"

'Reprotect file
ActiveDocument. Protect wdAllowOnlyForm Fields, NoReset:=True
End Sub

Any help would be really appreciated.

Thanks

Grant
Jul 17 '05 #1
0 6095

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
5151
by: Darryl Kerkeslager | last post by:
I hope that although this is 25% Access and 75% Word, that someone will know ... The whole problem here arises because 1) Microsoft acknowledges an 'issue' wherein TextInput type FormFields are lost when doing a MailMerge and 2) the fix that they have proposed is both inadequate and won't work from Access....
5
7970
by: steven | last post by:
Hello, I've created a Word-template for a letter. I've made some fields in the template (such as 'customer number', 'name', ...) as follows: insert field - DocVariabele with name 'customer number' and 'name'. Now I want to fill these fields from my application and print them: Dim myWord As New Word.Application...
3
1674
by: Joey | last post by:
Hello friends, somebody could help me to insert in a document of Word text that I go entering in 4 TextBox, in the word document I have placed markers in the places that I want that it is the text, in vb6 you toward by means of markers, but with VB.NET and office 2003 are lost. Thank you and greetings. -- Ceci est une signature automatique...
2
2373
by: roz | last post by:
Hello, I'm fairly new to VB programming and I've been going round the bend with this problem, so any nudges or shoves in the right direction would be greatly appreciated. I have a template form in Word. The information that I need to populate this form is from 2 tables in an Access 2002 database (patient details and GP details). Once the...
1
3387
by: jpr | last post by:
Friends, I am having problems in exporting data from my Access db to a word template. On my form I have a check box named check1. On my word template a have a box into which I need to export the value I enter in the check box. My checkbox in word is bookmarked. Something is not working proberly. The following code does not check
17
8684
by: wparrott | last post by:
Hello experts! I'm having trouble coding a button on a form and could use some help. In a nutshell, I'm attempting to code the button to do the following: 1. Choose the appropriate Word document 2. Fill in form fields on the doc using fields from the record 3. Print the document. 4. Close the word document suppressing any save dialogs. ...
0
1189
by: approtech | last post by:
Hi, My first post here so I hope this goes OK! I am using VBA in Excel 2003 (Windows XP) to cycle through a set of Word files which are questionnaire returns using form fields. It all works fine, but I hoped to get a way to read all the elements of the FormFields() array in each Word document in one pass per document, to reduce the time taken...
0
923
by: GOgier | last post by:
I am new to VB and struggling with the following Word form problem: I am designing a Word form whereby the collective values from 10 different dropdowns must be tested to ensure that any 2 combinations is valid against a set of established rules. For example; there are 10 dropdowns called Responsibility1, Responsibility2......
10
9232
by: mlevit | last post by:
Hi, I've found a tutorial that shows you how to fill in Word documents with values from Access 'Print customer slip for current customer. Dim appWord As Word.Application Dim doc As Word.Document 'Avoid error 429, when Word isn't open. On Error Resume Next Err.Clear
0
7664
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7885
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7638
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6250
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.