Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

empty form fields

Status
Not open for further replies.

RMCGAR

Mechanical
Jul 20, 2006
5
I'm trying to automate our price qoute sheet with a form i made with formfields in microsoft word. I have little experience with VBA and only in reference to excel. The form fields are within a three column eight row table with one form field in each cell. I would like a code that detects whether a form field Total7 is empty and if so deletes that entire row (row 8) from the table. It has been awhile sense i've done anything like this so any help would be great.

Thanks
Rory
 
Replies continue below

Recommended for you

You need to figure out how VBA addresses a formfield in Word (object browser is your friend here). Once you know what it's object name is, then you will do something like:

dim strContents as String
strContents = formfield("Total7").text

Once you've located the form field object in the object browser, you can hit F1 to call the help, which will have code examples and show you how to address it properly in your code.

A simple If statement or a Case statement will let you set the course for if it's empty or not.
 
Formfield values are accessed via: [tt]ActiveDocument.FormFields("Text7").Result[/tt]
Tables via (for example):
[tt]ActiveDocument.Tables(1).Rows(8).Delete[/tt]

Cheers,
Joerd

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
Thank you, I have managed to get that far on my own but have now hit another bug. Could anyone suggest a way to verify whether a formfield exists.

 
Two ways:
1. Loop through the formfields (For..Each) and verify the names to see if it matches the one you're looking for.
2. Set error trapping (On Error Goto xxx), call the formfield, and handle the error if it occurs.

Let me know if you can work it out based on these suggestions.

Cheers,
Joerd

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor