Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2005

Tip: Looking for answers? Try searching our database.

reposition text form fields via code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
seeker53 - 08 Apr 2005 15:13 GMT
I have two address lines in my template.  If one of the address lines is null
I want the other textboxes to shift so a blank line does not show on the
printout.

2.  I want to dynamically fill a form field combo box from a table in a
dbase.  How can this be done.
Doug Robbins - 09 Apr 2005 10:07 GMT
I would suggest that you switch over to a UserForm rather than use
formfields in a protected document.

See the article "How to create a Userform" at:

http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm

And, here's how you would populate a listbox (or a combobox with data from a
table in a database (Access)

Private Sub UserForm_Initialize()

   Dim db As DAO.Database

   Dim rs As DAO.Recordset

   Dim NoOfRecords As Long

   ' Open the database

   Set db = OpenDatabase("D:\Access\ResidencesXP.mdb")

   ' Retrieve the recordset

   Set rs = db.OpenRecordset("SELECT * FROM Owners")

   ' Determine the number of retrieved records

   With rs

        .MoveLast

        NoOfRecords = .RecordCount

        .MoveFirst

   End With

   ' Set the number of Columns = number of Fields in recordset

   ListBox1.ColumnCount = rs.Fields.Count

   ' Load the ListBox with the retrieved records

   ListBox1.Column = rs.GetRows(NoOfRecords)

   ' Cleanup

   rs.Close

   db.Close

   Set rs = Nothing

   Set db = Nothing

End Sub

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

>I have two address lines in my template.  If one of the address lines is
>null
[quoted text clipped - 3 lines]
> 2.  I want to dynamically fill a form field combo box from a table in a
> dbase.  How can this be done.
seeker53 - 11 Apr 2005 15:53 GMT
thank you for the suggestion.  I am useing formfields dropdown and the
following code does not work:  ActiveDocument.formfields("dropdown1").result
= rs.getrows(noOfRecords).  It tells me that there is a type mismatch.  Is
there a better newsgroup to use than this userform one?

> I would suggest that you switch over to a UserForm rather than use
> formfields in a protected document.
[quoted text clipped - 61 lines]
> > 2.  I want to dynamically fill a form field combo box from a table in a
> > dbase.  How can this be done.
Dian D. Chapman, MVP - 22 Apr 2005 23:44 GMT
Try this in place of that line...

Dim strCount As String

strCount = Cstr(rs.getrows(noOfRecords))

ActiveDocument.FormFields("dropdown1"). Result = strCount

Dian D. Chapman, Technical Consultant
Microsoft MVP, MOS Certified
Editor/TechTrax Ezine

Free MS Tutorials: http://www.mousetrax.com/techtrax
Free Word eBook: http://www.mousetrax.com/books.html
Optimize your business docs: http://www.mousetrax.com/consulting
Learn VBA the easy way: http://www.mousetrax.com/techcourses.html

>thank you for the suggestion.  I am useing formfields dropdown and the
>following code does not work:  ActiveDocument.formfields("dropdown1").result
[quoted text clipped - 66 lines]
>> > 2.  I want to dynamically fill a form field combo box from a table in a
>> > dbase.  How can this be done.
Dian D. Chapman, MVP - 22 Apr 2005 23:47 GMT
>Is  there a better newsgroup to use than this userform one?

Not BETTER than this group...but different. This group caters to a lot
of newbies learning VBA...

http://groups.yahoo.com/group/Word_VBA/

Dian D. Chapman, Technical Consultant
Microsoft MVP, MOS Certified
Editor/TechTrax Ezine

Free MS Tutorials: http://www.mousetrax.com/techtrax
Free Word eBook: http://www.mousetrax.com/books.html
Optimize your business docs: http://www.mousetrax.com/consulting
Learn VBA the easy way: http://www.mousetrax.com/techcourses.html
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.