Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-13-2015, 12:00 PM
brent chadwick brent chadwick is offline Help with if then statements Windows 8 Help with if then statements Office 2013
Advanced Beginner
Help with if then statements
 
Join Date: Mar 2015
Posts: 86
brent chadwick is on a distinguished road
Default Help with if then statements

Hey Guys,
I have a user form with a pull-down menu that i would like to insert a new form field with certain pull-down results. Example, if pull-down "DD1" = "1000", then insert form field (text box). Suggestions? Thanks
Reply With Quote
  #2  
Old 07-13-2015, 01:20 PM
gmaxey gmaxey is offline Help with if then statements Windows 7 32bit Help with if then statements Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

If Me.DD1.Value = "1000" then
ActiveDocument.FormFields.Add Selection.Range, wdFieldFormTextInput
End if
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 07-13-2015, 02:13 PM
brent chadwick brent chadwick is offline Help with if then statements Windows 8 Help with if then statements Office 2013
Advanced Beginner
Help with if then statements
 
Join Date: Mar 2015
Posts: 86
brent chadwick is on a distinguished road
Default

Thanks Greg for your reply. I get compile error-"invalid use of the keyword Me." I looked that one up and Me is only supposed to used in "class" modules. What can I substitute for it? Thanks-
Reply With Quote
  #4  
Old 07-13-2015, 02:18 PM
gmaxey gmaxey is offline Help with if then statements Windows 7 32bit Help with if then statements Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Me is the userform class object. The code could go in the DD click event or a command button click event. You don't really have to use Me.

If DD1.Value =

Should work as well
Reply With Quote
  #5  
Old 07-13-2015, 02:37 PM
brent chadwick brent chadwick is offline Help with if then statements Windows 8 Help with if then statements Office 2013
Advanced Beginner
Help with if then statements
 
Join Date: Mar 2015
Posts: 86
brent chadwick is on a distinguished road
Default

Still stalling on the If line. This is an exit macro when the drop-down is selected. Here's the code, hope I'm posting correctly-if not correct me. Thanks

Code:
Sub LockDD1()
'
' Lock DD1 Macro
'
'
          Application.ScreenUpdating = False
    If ActiveWindow.View.Type = wdPageView Then
        ActiveWindow.ActivePane.View.Type = wdNormalView
    Else
        ActiveWindow.View.Type = wdPageView
    End If
    If ActiveWindow.ActivePane.View.Type = wdNormalView Then
        ActiveWindow.ActivePane.View.Type = wdPageView
    Else
        ActiveWindow.ActivePane.View.Type = wdNormalView
    End If
    If DD1.Value = "1790" Then
    
     'Column box
    ActiveDocument.FormFields.Add Selection.Range, wdFieldFormTextInput
    Selection.PreviousField.Select
    With Selection.FormFields(1)
        .Name = "Column1790"
        .Enabled = True
        With .TextInput
            .EditType Type:=wdRegularText, Default:="X", Format:= _
                "Lower case"
            .Width = 0
        End With
    End With
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.TypeText Text:=", "
    



End If
    
End Sub
Reply With Quote
  #6  
Old 07-13-2015, 02:59 PM
gmaxey gmaxey is offline Help with if then statements Windows 7 32bit Help with if then statements Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Again, the code I provided would go in the UserForm DD1_Click event or a command button click event of the userform. If you want to use DD1 in an external procedure as you've done then you would need to passed a form object as an argument to the that procedure e.g.,

In a UserForm command button click event procefure

LockDD1 Me

In an external procedure:

Sub LockDD1(oFrm as Object)
Msgbox oFrm.DD1.Value
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #7  
Old 07-13-2015, 03:46 PM
brent chadwick brent chadwick is offline Help with if then statements Windows 8 Help with if then statements Office 2013
Advanced Beginner
Help with if then statements
 
Join Date: Mar 2015
Posts: 86
brent chadwick is on a distinguished road
Default

I'm a novice, you just lost me.
Reply With Quote
  #8  
Old 07-13-2015, 04:03 PM
gmaxey gmaxey is offline Help with if then statements Windows 7 32bit Help with if then statements Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

You said you had a userform with a dropdown DD1. A userform is a class module with properties, methods and events. If you have a dropdown in your Userform then there is a click event for that dropdown. If you have a command button in the userform then there is a click event for that command button.

Put the code I sent to you in one of those events.

Look at the create and employ a userform tips page on my website.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #9  
Old 07-13-2015, 06:01 PM
brent chadwick brent chadwick is offline Help with if then statements Windows 8 Help with if then statements Office 2013
Advanced Beginner
Help with if then statements
 
Join Date: Mar 2015
Posts: 86
brent chadwick is on a distinguished road
Default

I looked up the definition for user form and it appears that I misspoke. I do not have a user form but a Word doc with form fields in it-my bad. Now it makes sense that I was looking for a class module and other things that i don't have.

So I have a Word doc with form fields, and I want a macro to insert an additional form field if one of the items in a pull-down menu is chosen.
Thanks for your help, I have a lot to learn-
Reply With Quote
  #10  
Old 07-13-2015, 11:00 PM
macropod's Avatar
macropod macropod is offline Help with if then statements Windows 7 64bit Help with if then statements Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Inserting the new item is easy enough, but you also need to be able to delete it again if the user changes the dropdown selection. The following code should suffice. See attached demo.
Code:
Sub OptTxtFmFld()
Dim Prot As Variant, BmkRng As Range
Const Pwd As String = "" 'Insert password here
Const BmkNm As String = "BkMk" ' The bookmark name
With ActiveDocument
  Prot = .ProtectionType
  If .ProtectionType <> wdNoProtection Then
    Prot = .ProtectionType
    .Unprotect Password:=Pwd
  End If
  If .Bookmarks.Exists(BmkNm) Then
    Set BmkRng = .Bookmarks(BmkNm).Range
    If .FormFields("Dropdown1").Result = "1000" Then
      .FormFields.Add BmkRng, wdFieldFormTextInput
    Else
      BmkRng.Delete
    End If
    .Bookmarks.Add BmkNm, BmkRng
  Else
    MsgBox "Bookmark: " & BmkNm & " not found."
  End If
  .Protect Type:=Prot, Password:=Pwd, NoReset:=True
End With
Set BmkRng = Nothing
End Sub
Attached Files
File Type: docm FormFieldDemo.docm (30.5 KB, 21 views)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 07-14-2015, 05:22 AM
brent chadwick brent chadwick is offline Help with if then statements Windows 8 Help with if then statements Office 2013
Advanced Beginner
Help with if then statements
 
Join Date: Mar 2015
Posts: 86
brent chadwick is on a distinguished road
Default

So what you are saying is that this code should be added to the exit macro of the drop-down menu?
Reply With Quote
  #12  
Old 07-14-2015, 05:31 AM
macropod's Avatar
macropod macropod is offline Help with if then statements Windows 7 64bit Help with if then statements Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

From the dropdown formfield's properties, choose the 'OptTxtFmFld' macro for the 'On Exit' property. You will also need a bookmark named 'BkMk' where you want the conditional field to go.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #13  
Old 07-14-2015, 08:05 AM
brent chadwick brent chadwick is offline Help with if then statements Windows 8 Help with if then statements Office 2013
Advanced Beginner
Help with if then statements
 
Join Date: Mar 2015
Posts: 86
brent chadwick is on a distinguished road
Default

I need a little explanation on the bookmarks-is it one that exists in the document or the one that will be created by the new form field? I have tried both and I get the message box that they do not exist-Thanks
Reply With Quote
  #14  
Old 07-14-2015, 08:12 AM
brent chadwick brent chadwick is offline Help with if then statements Windows 8 Help with if then statements Office 2013
Advanced Beginner
Help with if then statements
 
Join Date: Mar 2015
Posts: 86
brent chadwick is on a distinguished road
Default

Just a thought, would it be easier to insert all of the form fields and delete the ones not used when the drop-down is chosen?
Reply With Quote
  #15  
Old 07-14-2015, 03:06 PM
macropod's Avatar
macropod macropod is offline Help with if then statements Windows 7 64bit Help with if then statements Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The bookmark named 'BkMk' is one you create in the document, via Insert|Bookmark. You can use another name, of course, but you need to use the same name in both the document and the macro.
Quote:
would it be easier to insert all of the form fields and delete the ones not used when the drop-down is chosen?
No, because you'd still have to be able to add them back in if the user changes their mind.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with if then statements Multiple If statements, Jamal NUMAN Excel 16 11-15-2022 11:59 PM
Countif statements Alaska1 Excel 5 02-05-2015 07:55 PM
Help with if then statements Using IF statements stuwoolf Excel 2 01-10-2015 01:58 PM
Help with if then statements count if statements Alaska1 Excel 1 05-14-2014 08:21 AM
IF statements that shifts to right. kent Excel 0 01-19-2006 02:23 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:36 PM.


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