question

mmmmmmm-1736 avatar image
0 Votes"
mmmmmmm-1736 asked mmmmmmm-1736 published

VBA Word-If a User Form textbox is left empty then delete the entire row in a table in a word document

(Doc1 and Doc2 are both public in a module and chosen using a file selector)

I have this code below that lets users fill out textboxx25 if it is relevant to a user but it can be left blank. The text box is set up so that if the date is after 11/12/2020 then what is entered into the text box will go onto doc1 and doc2 will be left empty and vice versa if the date is before than. How could I set this up so that if it is left empty it will delete the entire row in the table?



The table looks like-
[textbox1] [textbox7] [textbox13] [textbox19] [textbox25] [textbox31]

 Private Sub CommandButton1_Click()
    
 Dim s As String
    
 s = Me.TextBoxx25.Text
    
 If s = "" Then
    
 ElseIf DateDiff("d", s, Me.TextBoxx25.Text, "11/12/2020") > 0 Then
    
 Doc1.Variables("TextBoxx25").Value = " "
    
 Doc1.Variables("TextBoxx1").Value = " "
    
 Doc1.Variables("TextBoxx7").Value = " "
    
 Doc1.Variables("TextBoxx13").Value = " "
    
 Doc1.Variables("TextBoxx19").Value = " "
    
 Doc1.Variables("TextBoxx31").Value = " "
    
 Doc2.Variables("TextBoxx25").Value = Me.TextBoxx25.Text
    
 Doc2.Variables("TextBoxx1").Value = Me.TextBoxx1.Text
    
 Doc2.Variables("TextBoxx7").Value = Me.TextBoxx7.Text
    
 Doc2.Variables("TextBoxx13").Value = Me.TextBoxx13.Text
    
 Doc2.Variables("TextBoxx19").Value = Me.TextBoxx19.Text
    
 Doc2.Variables("TextBoxx31").Value = Me.TextBoxx31.Text
    
 Else
    
 Doc1.Variables("TextBoxx25").Value = Me.TextBoxx25.Text
    
 Doc1.Variables("TextBoxx1").Value = Me.TextBoxx1.Text
    
 Doc1.Variables("TextBoxx7").Value = Me.TextBoxx7.Text
    
 Doc1.Variables("TextBoxx13").Value = Me.TextBoxx13.Text
    
 Doc1.Variables("TextBoxx19").Value = Me.TextBoxx19.Text
    
 Doc1.Variables("TextBoxx31").Value = Me.TextBoxx31.Text
    
 Doc2.Variables("TextBoxx25").Value = " "
    
 Doc2.Variables("TextBoxx1").Value = " "
    
 Doc2.Variables("TextBoxx7").Value = " "
    
 Doc2.Variables("TextBoxx13").Value = " "
    
 Doc2.Variables("TextBoxx19").Value = " "
    
 Doc2.Variables("TextBoxx31").Value = " "
    
 End If
    
 Doc1.Range.Fields.Update
    
 Doc2.Range.Fields.Update
    
 End Sub

'Thanks in advance!

office-vba-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

0 Answers