Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-19-2024, 07:59 PM
rimmerthecat rimmerthecat is offline how to clear a text box in a form in word Windows 10 how to clear a text box in a form in word Office 2021
Novice
how to clear a text box in a form in word
 
Join Date: Jun 2024
Posts: 4
rimmerthecat is on a distinguished road
Talking how to clear a text box in a form in word

greetings, absloute newbie here, i did some very basic vba coding about 20 years ago, now im creating a form for where i work now, ive got text boxes i need to clear after theyve been added to a doccument with a button, is there a simple line of code to do so?



any suggestions woud be greatly appriciated
thanks
Reply With Quote
  #2  
Old 06-20-2024, 04:49 AM
gmaxey gmaxey is offline how to clear a text box in a form in word Windows 10 how to clear a text box in a form in word Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,601
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

What kind of textboxes? What kind of button?
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 06-20-2024, 03:49 PM
rimmerthecat rimmerthecat is offline how to clear a text box in a form in word Windows 10 how to clear a text box in a form in word Office 2021
Novice
how to clear a text box in a form in word
 
Join Date: Jun 2024
Posts: 4
rimmerthecat is on a distinguished road
Default

just the normal default text box, and a standard command button
Reply With Quote
  #4  
Old 06-20-2024, 05:57 PM
Guessed's Avatar
Guessed Guessed is offline how to clear a text box in a form in word Windows 10 how to clear a text box in a form in word Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,166
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You are asking for clearing a text box and we would need more information on how to determine which text box. It is certainly possible to do this but the macro needs to be set up with some kind of input parameters eg
Are we clearing every text box in the document
Are we clearing a specific text box (how will the macro know which text box to clear)
Are we clearing a selected text box
If you already have a button that adds a text box, wouldn't it be better to delete the text box rather than emptying it?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 06-20-2024, 07:18 PM
rimmerthecat rimmerthecat is offline how to clear a text box in a form in word Windows 10 how to clear a text box in a form in word Office 2021
Novice
how to clear a text box in a form in word
 
Join Date: Jun 2024
Posts: 4
rimmerthecat is on a distinguished road
Default

very basically im creating a form to use to record the purchase of scrap metal, more often than not a customer has more than one type of metal, what id like to happen is you enter the type of metal into a text box on a form, click a button and the data is transferred to a doccument and the text box is cleared ready for a second type of metal etc

here is what i have at the moment, apologies im sure it looks horrible

:
Private Sub ADDCOMMODITY_Click()
Selection.GoTo What:=wdGoToBookmark, Name:="COMMODITY"
Selection.TypeText Text:=COMMODITYBOX
Selection.TypeParagraph

End Sub

hope this is helpful
Reply With Quote
  #6  
Old 06-20-2024, 07:38 PM
Guessed's Avatar
Guessed Guessed is offline how to clear a text box in a form in word Windows 10 how to clear a text box in a form in word Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,166
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Yeah, yeah, nah. That isn't actually helpful because:
1. there is no text box associated with that code
2. the text that was added by that code is sitting beside the bookmark and not actually inside the bookmark.

It is probably easiest if you post a sample document and your current code so we can suggest modifications that would then work happily with your existing code. If the macro is asking for a metal type and using that info in another document, why bother writing it to this document at all?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #7  
Old 06-20-2024, 07:51 PM
rimmerthecat rimmerthecat is offline how to clear a text box in a form in word Windows 10 how to clear a text box in a form in word Office 2021
Novice
how to clear a text box in a form in word
 
Join Date: Jun 2024
Posts: 4
rimmerthecat is on a distinguished road
Default

i will attempt to explain further, to eliminate issues reading handwriting we would like to use a vba form to enter the relevant information onto a doccument that will then be sent into the office to process payment


heres the complete code so far:
Private Sub ADDCOMMODITY_Click()
Selection.GoTo What:=wdGoToBookmark, Name:="COMMODITY"
Selection.TypeText Text:=COMMODITYBOX
Selection.TypeParagraph

End Sub

Private Sub ADDWEIGHT_cLICK()
Selection.GoTo What:=wdGoToBookmark, Name:="WEIGHT"
Selection.TypeText Text:=WEIGHTBOX
Selection.TypeParagraph
End Sub

Private Sub COMMODITYBOX_Change()

End Sub

Private Sub FINISH_Click()
Unload NFfrm
End Sub

Private Sub REGOTXT_Change()

End Sub

Private Sub regsave_Click()
Selection.GoTo What:=wdGoToBookmark, Name:="rego"
Selection.TypeText Text:=REGOTXT
End Sub

Private Sub WEIGHTBOX_Change()

End Sub

hope this is more useful
Attached Files
File Type: docx SHED SHEET TESTING JASON.docx (20.0 KB, 7 views)
Reply With Quote
  #8  
Old 06-22-2024, 08:54 PM
Guessed's Avatar
Guessed Guessed is offline how to clear a text box in a form in word Windows 10 how to clear a text box in a form in word Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,166
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Your code adds text alongside the bookmark, not inside the bookmark so it is hard to then clear that with other code. Rather than doing the extra steps to rectify that, I'm going to suggest what I consider a better alternative.

Your sample document doesn't include any code or userform information so it isn't immediately apparent what benefit you get out of using VBA so I'm going to suggest you perhaps consider getting rid of all the complexity of the userform and VBA and just go back to basics.
1. Set up your document with Content Controls instead of bookmark locations
2. Protect the document so the user can only edit the Content Controls
3. Save the document as a template so that you create new docs each time you want a 'cleared' form.

An alternative to #3 is to include a macro to clear the Content Controls (aka your original request before I drifted off on a tangent because bookmarks weren't as flexible as content controls and you haven't yet convinced me as to why a VBA userform was involved). Macros to clear all CCs or write to a specific one are below
Code:
Sub ClearCCs()
  Dim aCC As ContentControl
  For Each aCC In ActiveDocument.ContentControls
    aCC.Range.Text = ""
  Next aCC
End Sub

Sub WriteToCC()
  Dim aCC As ContentControl
  For Each aCC In ActiveDocument.SelectContentControlsByTitle("Rego")
    aCC.Range.Text = "This is the rego"
  Next aCC
End Sub
Attached Files
File Type: docm SHED SHEET TESTING JASON.docm (40.1 KB, 2 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia

Last edited by Guessed; 06-23-2024 at 04:16 PM.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to clear a text box in a form in word Reset "Button" to clear Word user-filled form, from all filled details. Rafi Word VBA 20 01-20-2023 02:16 PM
Clear all content controls (Text, dropdown) AND change option button values to FALSE in MS Word Form Janet D Word VBA 7 01-14-2023 02:36 AM
Clear Values from All Controls on Form ScottyBee Word VBA 2 04-02-2019 09:55 AM
how to clear a text box in a form in word Word Form to Save as and clear sfitzsimmons Word VBA 1 01-11-2019 02:03 PM
how to clear a text box in a form in word Don't clear form fields when protecting as a form BruceM Word 5 10-06-2016 08:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:37 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft