Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

Add new row in form table only when a field is not blank 1

Status
Not open for further replies.

remeng

Technical User
Jul 27, 2006
520
US
Hi All;

I am trying to add a new row in a table only when the last field in the table is not blank. Currently I have the code for adding the line and blank fields. I can run the code when the field is exited without any issues.

Several things that I would like to do:

1) I want to only activate this on the last field on the last row of the table only if it is not blank
2) I don't know how to do this based on a random field bookmark name that is created from the following code
3) How do I de-activate the code in any lines above the new blank table row and field where this code has already been been run

The code currently activates on the exiting of form field. There are some issues.

1) If statement is not correctly activating due to me not knowing the proper formula to activate the if statement
2) In the second with statement, I don't know how to update the form field name from the current name "Text52" to the newly created form field
3) Other issues are also occuring

any assistance would be appreciated.

Mike

Code:
Sub test()

If Selection.FormFields > 0 Then

Selection.InsertRowsBelow 1

    Selection.FormFields.Add Range:=Selection.Range, Type:= _
        wdFieldFormTextInput
    Selection.MoveRight Unit:=wdCell
    Selection.FormFields.Add Range:=Selection.Range, Type:= _
        wdFieldFormTextInput
    Selection.MoveRight Unit:=wdCell
    Selection.FormFields.Add Range:=Selection.Range, Type:= _
        wdFieldFormTextInput
    Selection.MoveRight Unit:=wdCell
    Selection.FormFields.Add Range:=Selection.Range, Type:= _
        wdFieldFormTextInput
        
    With Selection.FormFields(1)
    With Selection.FormFields
    
        '.Name = "Text52"
        .EntryMacro = ""
        .ExitMacro = "test"
        .Enabled = True
        .OwnHelp = False
        .HelpText = ""
        .OwnStatus = False
        .StatusText = ""
        With .TextInput
            .EditType Type:=wdRegularText, Default:="", Format:=""
            .Width = 0
        End With
    End With
    

Else: End If

End Sub
 
Hi Skip,

Sometime the basics are missed. Thanks for the help. The extra line was added.

I think I should be able to proceed with this code.

I will also add a button to add the extra line just in case.

Thanks for the help.
 
Even if you don’t use it, you ought to look at macropod’s code and try to understand what he’s doing. I’m sure that it will be enlightening. I’ve learned an awful lot just by looking at other people’s solutions and tucking little gems away in my toolbox.

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top