On Open event to clear all form fields or not..

I have the following code in my OnOpen event of my word document
form.  As long as you answer "Yes" to the msg box the code works fine,
but if you say no, then it exposes rows in my form that contain VBA
buttons and radio buttons.

Can anyone help me out with how to fix this?

Thanks so much....

Here is the code:

Dim myFormField As FormField
Dim aDoc As Document
Dim response
Dim msg As String


Set aDoc = ActiveDocument
msg = "Do you want to clear all FormField results?"
response = MsgBox(msg, vbYesNo)
If response = vbYes Then
  For Each myFormField In aDoc.FormFields()
    Select Case myFormField.Type
      Case 70  ' text
        ' checks to see if there is default text
        ' if yes, removes user inout and
        ' reverts to default; if no, removes user input
        If myFormField.TextInput.Default <> "" Then
          myFormField.Result = myFormField.TextInput.Default
        Else
          myFormField.Result = ""
        End If
      Case 71  ' check
        myFormField.Result = False
      Case 83   ' dropdown
        myFormField.DropDown.Value = 1

    End Select
0
Worsty
1/14/2010 3:22:22 PM
word.vba.general 1023 articles. 0 followers. Follow

3 Replies
1350 Views

Similar Articles

[PageSpeed] 0

" if you say no, then it exposes rows in my form that contain VBA
buttons and radio buttons."

Could elaborate on this?  As is, I see no connection.  Where these hidden in
some way?  What do you mean "expose"?

Worsty wrote:
>I have the following code in my OnOpen event of my word document
>form.  As long as you answer "Yes" to the msg box the code works fine,
>but if you say no, then it exposes rows in my form that contain VBA
>buttons and radio buttons.
>
>Can anyone help me out with how to fix this?
>
>Thanks so much....
>
>Here is the code:
>
>Dim myFormField As FormField
>Dim aDoc As Document
>Dim response
>Dim msg As String
>
>Set aDoc = ActiveDocument
>msg = "Do you want to clear all FormField results?"
>response = MsgBox(msg, vbYesNo)
>If response = vbYes Then
>  For Each myFormField In aDoc.FormFields()
>    Select Case myFormField.Type
>      Case 70  ' text
>        ' checks to see if there is default text
>        ' if yes, removes user inout and
>        ' reverts to default; if no, removes user input
>        If myFormField.TextInput.Default <> "" Then
>          myFormField.Result = myFormField.TextInput.Default
>        Else
>          myFormField.Result = ""
>        End If
>      Case 71  ' check
>        myFormField.Result = False
>      Case 83   ' dropdown
>        myFormField.DropDown.Value = 1
>
>    End Select

-- 
Message posted via http://www.officekb.com

0
Fumei2
1/14/2010 7:23:06 PM
While your syntax appears a tad awry - try the following - I too don't see 
the connection between your code and the hidden data.

Dim myFormField As FormField
Dim aDoc As Document
Dim response
Dim msg As String
Set aDoc = ActiveDocument
msg = "Do you want to clear all FormField results?"
response = MsgBox(msg, vbYesNo)
If response = vbYes Then
    For Each myFormField In aDoc.FormFields()
        Select Case myFormField.Type
            Case 70  ' text
                ' checks to see if there is default text
                ' if yes, removes user inout and
                ' reverts to default; if no, removes user input
                If myFormField.TextInput.Default <> "" Then
                    myFormField.Result = myFormField.TextInput.Default
                Else
                    myFormField.Result = ""
                End If
            Case 71  ' check
                myFormField.CheckBox.Value = 0
            Case 83   ' dropdown (selects first item in list)
                myFormField.DropDown.Value = 1
        End Select
    Next myFormField
End If


-- 
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Worsty" <dworst@gaic.com> wrote in message 
news:263f0b2a-4282-4e6b-b68f-04e0484c1bee@j5g2000yqm.googlegroups.com...
>I have the following code in my OnOpen event of my word document
> form.  As long as you answer "Yes" to the msg box the code works fine,
> but if you say no, then it exposes rows in my form that contain VBA
> buttons and radio buttons.
>
> Can anyone help me out with how to fix this?
>
> Thanks so much....
>
> Here is the code:
>
> Dim myFormField As FormField
> Dim aDoc As Document
> Dim response
> Dim msg As String
>
>
> Set aDoc = ActiveDocument
> msg = "Do you want to clear all FormField results?"
> response = MsgBox(msg, vbYesNo)
> If response = vbYes Then
>  For Each myFormField In aDoc.FormFields()
>    Select Case myFormField.Type
>      Case 70  ' text
>        ' checks to see if there is default text
>        ' if yes, removes user inout and
>        ' reverts to default; if no, removes user input
>        If myFormField.TextInput.Default <> "" Then
>          myFormField.Result = myFormField.TextInput.Default
>        Else
>          myFormField.Result = ""
>        End If
>      Case 71  ' check
>        myFormField.Result = False
>      Case 83   ' dropdown
>        myFormField.DropDown.Value = 1
>
>    End Select 


0
Graham
1/15/2010 10:59:39 AM
On Jan 15, 5:59=A0am, "Graham Mayor" <gma...@REMOVETHISmvps.org> wrote:
> While your syntax appears a tad awry - try the following - I too don't se=
e
> the connection between your code and the hidden data.
>
> Dim myFormField As FormField
> Dim aDoc As Document
> Dim response
> Dim msg As String
> Set aDoc =3D ActiveDocument
> msg =3D "Do you want to clear all FormField results?"
> response =3D MsgBox(msg, vbYesNo)
> If response =3D vbYes Then
> =A0 =A0 For Each myFormField In aDoc.FormFields()
> =A0 =A0 =A0 =A0 Select Case myFormField.Type
> =A0 =A0 =A0 =A0 =A0 =A0 Case 70 =A0' text
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ' checks to see if there is default text
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ' if yes, removes user inout and
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ' reverts to default; if no, removes user=
 input
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 If myFormField.TextInput.Default <> "" Th=
en
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 myFormField.Result =3D myFormFiel=
d.TextInput.Default
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Else
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 myFormField.Result =3D ""
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 End If
> =A0 =A0 =A0 =A0 =A0 =A0 Case 71 =A0' check
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 myFormField.CheckBox.Value =3D 0
> =A0 =A0 =A0 =A0 =A0 =A0 Case 83 =A0 ' dropdown (selects first item in lis=
t)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 myFormField.DropDown.Value =3D 1
> =A0 =A0 =A0 =A0 End Select
> =A0 =A0 Next myFormField
> End If
>
> --
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor - =A0Word MVP
>
> My web sitewww.gmayor.com
> Word MVP web sitehttp://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
> Worsty" <dwo...@gaic.com> wrote in message
>
> news:263f0b2a-4282-4e6b-b68f-04e0484c1bee@j5g2000yqm.googlegroups.com...
>
>
>
> >I have the following code in my OnOpen event of my word document
> > form. =A0As long as you answer "Yes" to the msg box the code works fine=
,
> > but if you say no, then it exposes rows in my form that contain VBA
> > buttons and radio buttons.
>
> > Can anyone help me out with how to fix this?
>
> > Thanks so much....
>
> > Here is the code:
>
> > Dim myFormField As FormField
> > Dim aDoc As Document
> > Dim response
> > Dim msg As String
>
> > Set aDoc =3D ActiveDocument
> > msg =3D "Do you want to clear all FormField results?"
> > response =3D MsgBox(msg, vbYesNo)
> > If response =3D vbYes Then
> > =A0For Each myFormField In aDoc.FormFields()
> > =A0 =A0Select Case myFormField.Type
> > =A0 =A0 =A0Case 70 =A0' text
> > =A0 =A0 =A0 =A0' checks to see if there is default text
> > =A0 =A0 =A0 =A0' if yes, removes user inout and
> > =A0 =A0 =A0 =A0' reverts to default; if no, removes user input
> > =A0 =A0 =A0 =A0If myFormField.TextInput.Default <> "" Then
> > =A0 =A0 =A0 =A0 =A0myFormField.Result =3D myFormField.TextInput.Default
> > =A0 =A0 =A0 =A0Else
> > =A0 =A0 =A0 =A0 =A0myFormField.Result =3D ""
> > =A0 =A0 =A0 =A0End If
> > =A0 =A0 =A0Case 71 =A0' check
> > =A0 =A0 =A0 =A0myFormField.Result =3D False
> > =A0 =A0 =A0Case 83 =A0 ' dropdown
> > =A0 =A0 =A0 =A0myFormField.DropDown.Value =3D 1
>
> > =A0 =A0End Select- Hide quoted text -
>
> - Show quoted text -

Thanks so much.....I'll work on this and get back to you.
0
Worsty
1/15/2010 9:17:38 PM
Reply:

Similar Artilces:

code to allow edits in form AND subform
Ok, here goes............. I have a form (frmBOL) which contains a subform (sfrmData). I have this code working to allow the form to be edited, but I can't seem to incorporate the subform into it. Everything I try gives me an error. Can anyone help? Private Sub cmdOK_Click() Dim sPassword As String sPassword = Nz(Me.txtPassword.Value, "") ' if it is a valid password, we let them edit the ' form that called this form. The calling form is ' responsible for check that the current user is ' either the QA tech on the record, or a me...

when i open an attachment it just shows a box i cannot open
Attachment, whether docs or pictures won't open. I can preview them inside the window pane, but then have to copy to word doc to print. Should be able to open attachment and then print just from there. Please help. It's like the Microsoft Picture manager is working strangely. ...

Opening a paramater form when open a report
I have a repor that takes date parameters from a seperate form.. As it is now I have to open the form put in the paramaters and then run the report which is based on a query... I would like to have the form pop up when I open the report and then close once once the report has run.. Help Please And thanks in advance bob On Wed, 15 Aug 2007 11:56:00 -0700, Bob wrote: > I have a repor that takes date parameters from a seperate form.. As it is now > I have to open the form put in the paramaters and then run the report which > is based on a query... > > I would like to ...

How do I get my MS Pub 2000 to open Pub files from Pub 2003?
i cannot get my Publisher 2000 to open files from Pub 2003....do i have to buy Pub 2003? or is there a solution that I can download? I have already disabled my antivirus and that didn't do anything.. also my files are not "read only". pls help. thx. Novice Novice <Novice@discussions.microsoft.com> was very recently heard to utter: > i cannot get my Publisher 2000 to open files from Pub 2003....do i > have to buy Pub 2003? or is there a solution that I can download? I > have already disabled my antivirus and that didn't do anything.. also > my files ...

Publisher 2000
After I open the Publisher 2000 program and attempt to open a file or create a new document, I get the message "Microsoft Publisher 2000 Version 6.0 has encoountered a problem and needs to close. WE are sorry for the inconvenience". I tried repairing the program and even reinstalling it, but that did not correct it. Suggestions? If you are trying to use Publisher on a network - don't it is not intended for a network Publisher files have to be worked on and saved to the local hard drive ONLY. -- Hi tom (tevanz@bellsouth.net), in the Microsoft� newsgroups you posted: ...

Problem trying to open old money file
Hi, I am trying to open a four-month old money file, which was on my backup disk. It is a *.mny file, not a backup file. It was created using the same version of Money (2005) which I still use. When I start MS MONEY and try open my old data file, it tells my that it wants convert my file so it works with this version. (Not sure why as the file was created in this version of MS Money). Then when I try and carry out the conversion it gives the following error message. "Money cannot locate xxxx or cannot open it, possibly because it is a read-only file or you do not have...

OL 2003 .nk2 file clears on reboot
We have a client machine whose NK2 file is cleared on reboot. We have tried creating deleting the nk2 file to have OL create a new one, created a new OL profile with no luck. When we copied another users nk2 file to his directory and renamed it to his profile the data is picked up, but no new address are stored. outlook writes to the file when it closes - so it seems outlook is not closing correctly. is there a pda or an application using outlook data? if so, close it first. -- Diane Poremsky [MVP - Outlook] Author, Teach Yourself Outlook 2003 in 24 Hours Need Help with Common Tasks? h...

opening links in outlook
why i can not open links attached to my e-mails mike wrote: >why i can not open links attached to my e-mails > I think you did some mistake in typing so just do one thing first type the link in notepad and then direct copy and paste that in your mail. -- Stellar Information Systems Ltd. D18, Sector-33, Infocity Phase II, Gurgaon-122001 Phone : (0124) 326 6069, 432 6700 Website : http://www.stellarinfo.co.in/ What happens when you try? Do you get the error; "This operation has been cancelled due to restrictions in effect on this computer" See http://www.m...

subform datasheet: one field does not show the values
I had created a subform for order details and linked this to orders form\ table by OrderId. All the details are showing up in my subform( datasheet view) except OrderNO, which is a text field. I am using Access 2007. Do any one of you experienced this kind of issue before? Thanks -- Message posted via http://www.accessmonster.com On Thu, 18 Mar 2010 15:47:54 GMT, "mls via AccessMonster.com" <u55943@uwe> wrote: >I had created a subform for order details and linked this to orders form\ >table by OrderId. All the details are showing up in my subform( data...

Running Virus Scan Slowing down opening files
3 minutes to open files in excel and word Are you using kaspersky virusscan? It is know for it. If yes please ask you administrator to exclude scan on harddisk or network files in the settings. -- Arien ------------------------------------------------------------------------ Arien's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1892 View this thread: http://www.excelforum.com/showthread.php?threadid=390878 All Virus Scanning can be stopped: If your using Norton Follow the below if you want to open documents much faster Open Norton Click on: Norton Interne...

Email with tiny attachments open slow
Good Day All, I am using Exchange server 200 and Outlook 2003 mail client. I have started to experience with a single machine where all of a sudden reading emails with attachments of any size, even 6k, slows greatly. Just selecting the email item in the list takes at least 30 seconds before the lower pane shows the body of the selected item. No other client has the same problem even while this machine does. The problem seems to disappear at some point and then returns. The machine was connected to a 10Mbps switch so I changed to a 100Mbps switch and Event logs reveal nothing. I have ...

Need an open house sign in sheet
Need an open house sign in sheet That's interesting, but do you have a question about Publisher? -- James Bart: "According to creationism, there were no cavemen." Homer: "Well good riddance, their drawings sucked and they all looked like hippies!" "soozeeque" <soozeeque@discussions.microsoft.com> wrote in message news:1096B15B-9766-4573-9FC2-2053BEC1F34B@microsoft.com... > Need an open house sign in sheet I would suggest keeping it simple. Use a table for the visitors' information and maybe your real estate company's logo...

Table to form
I have a field in a table called ID. 4 posititions. I have a field in a subform where I want to enter an ID. If the ID is not in the table, I want to know. How can I connect them? By the way, if it is not in the table, I would want a message to pop up or the ability to add to the table on the fly. Thanks. On Fri, 29 Jun 2007 10:36:25 -0500, "rob peterson" <buster@owc.net> wrote: >I have a field in a table called ID. 4 posititions. What do you mean by "positions"?? >I have a field in a subform where I want to enter an ID. If the ID is not in >the tabl...

How to clear the names when writing in the To: field...
Hi, How can I clear the list of names, that's showing up when I write in my To:/CC: field. Everytime I send an email to someone, they get's listed in this list - which means, everytime I write a name, I get a huge list... How can I avoid this? Thanks! /Rico After you type 3 letters in the To:/CC: box the names appear in the dropdown. If you use the down arrow to highlight the name you don't want to appear and then press the delete key. Hey preseto its gone. >-----Original Message----- >Hi, > >How can I clear the list of names, that's showing up when &...

opening links
Whenever I try to open a link in Outlook XP -- (Win XP Pro) it opens a "open with" prompt/box. Point it to the .exe for your preferred browser and click okay. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the Swen virus, all e-mails sent to my actual account will be deleted w/out reading. After searching google.groups.com and finding no answer anonymous@discussions.microsoft.com <anonymous@discussions.microsoft.com> asked: | Whenever I try to open a link in Outlook XP -- (Win XP | Pro) it opens a "open with&quo...

cannot open excel file from outlook
Excel 2007 cannot open document eithout first saving and opening thru excel Try to re-register Excel. Close Excel first and On the Windows Taskbar Start>Run "excel.exe /regserver"(no quotes)>OK. See the space between exe and /regserver You might have to designate a full path to excel.exe. In that case Start>Run "C:\yourpath\excel.exe" /regserver(quotes required)>OK Gord Dibben MS Excel MVP On Wed, 27 Jan 2010 11:38:12 -0800, Rick <Rick@discussions.microsoft.com> wrote: >Excel 2007 cannot open document eithout first savi...

unable to open your default mail folders...
I am running XP Pro and Office XP 2002. I currently use Outlook express on this PC but want to switch over to Outlook. When I try to open Outlook I get the message- Unable to open your default mail folders. Could not open item. Try again. Any ideas what's going on ??? Thanks in advance!!! -- Dennis Have you created a mail profile and installed your mail account(s)? -- Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. ALWAYS post your Outlook version. How to ask a question: http://support.microsoft.com/KB/555375 After furious head scrat...

Workbook always opens at a specific sheet and cell
I have a workbook consisting of many sheets. How do I make sure that everytime I open the work book, it would directly point to a specific sheet and cell? Hi put the following code in your workbook module (not in a standard module). sub workbook_open() me.worksheets("sheetx").activate end sub -- Regards Frank Kabel Frankfurt, Germany Zee wrote: > I have a workbook consisting of many sheets. How do I make sure that > everytime I open the work book, it would directly point to a specific > sheet and cell? methinks the original poster also wanted to activate a particu...

Exported form shows error
I exported a table and form to another database for use in another facility I operate. When I go to open the form, an error is displayed stating..."The record source '~sq_cSaidTable~sq_cList70' specified on this form or report does not exist" It then proceeds to alter the record souce in the form in design veiw. I have done that and the error persists. How do I repair this? -- Deltadog-Sacramento River Delta fisher extrodinairre... ...

EXCEL Files open Slow
Why is it that when I open associated files for Office 2007 (.xlsx and ..docx) that they open SLOW (approx 15 seconds). However, if I have Excel or Word open and then attempt to open specific files, they open in a snap ? I have Office 2007, Vista Home Prsmium, a 2.4 Quad Core system, and four gigs of ram. Can someone please explain this and help me out ? Thanks. Hi, If I get your point - when you open the files in the Window Explorer (outside of Excel) it takes longer. Sometimes that if because Excel needs to launch, and that can be slower than just opening a file from inside of Excel...

update many fields in a form from existing info.
I have 2 tables. One table stores various information about companies including company name, address, etc. The second table stores student names. In a form, I am able to enter mutiple student names into a memo field and, as of right now, type in the company name, address, etc. (it is not linked to the company name table at all). What I want to do is this: from the student add form, search the company table for a company based on partial name and/or zipcode, select one company from a possible 1 or more companies, and have the fields in the form automatically fill in - pulling the ...

Opening a second mdb file from an open mdb file
I have two mdb files (one used for general department use and the other for detailed reporting). For ease of maintenance, I'd like to keep these mdb files separate, but I would like to have the ability to open the second mdb file from the general dept Access program. Is there an exisitng macro or VBA code I could use to accomplish this task? Thanks for your help. Sure, you can easily just shell out to another app: http://www.mvps.org/access/api/api0018.htm or even create a hyperlink that opens the file. Just create a label, go to the property sheet and enter a path in the hype...

Directory Open
Hi, I would like to create a Button which opens a dialog box, not to open a file but to open a directory. How should I do it? I thought of using CFileDialog but it does not allow for opening just a directory and not a file. I just want to read in the user selection of directory and the file name will be set in my application. Thanks! On Wed, 17 Dec 2003 22:15:36 -0800, Dave wrote: > I would like to create a Button which opens a dialog box, > not to open a file but to open a directory. > > How should I do it? > I thought of using CFileDialog but it does not allow for ...

Controlling a PivotChart using a form
Hi, I'm trying to make a form that displays a pivot chart which reflects changes a user makes on a series of listboxes on the form. Whats the best way to go about doing this? I have 2 list boxes that will narrow the selection down (ie by 'category' and 'dates' - 'dates' being multiselection) and I have a listbox which is to select what data is shown on the pivot chart (a range of values at certain percentage levels). What I want to do is have the user pick a category, a date(s) and then a percentage amount, click a button and the pivotchart updates with the relev...

running forms on desktop
hi all, i couldn't find an answer to this one, and i was hoping to run a small phone no. database on my desktop, that is, without the Access Program window in the background. So my 2 small forms would appear on the desktop itself. i have Access 2003 and WinXp Sp2 thanks in advance Dave See whether what's presented in http://www.mvps.org/access/api/api0019.htm at "The Access Web" does what you want. -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Dave Smith" <steens@indigo.net.au> wrote in message news:OCZzlurzH...