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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User Input through Form in Word 2

Status
Not open for further replies.

RCorrigan

MIS
Feb 24, 2004
2,872
MT
I have a doc that I want to pass input to using a form.
I have designed the form

there is a frame with two option buttons in
8 txt boxes, a combo box, another frame with 5 check boxes in and then three cmd buttons OK, Clear & cancel

The idea is that if new is chosen from the 1 st option then you see so many of the txt boxes and if Modify you see a different selection

What I have so far is

Code:
Private Sub UserForm_Initialize()

         With cboAccess
        .AddItem "Input"
        .AddItem "Enquirer"
        .AddItem "Authoriser A"
        .AddItem "Authoriser B"
        .AddItem "Remove"
    End With
    
End Sub

    Private Sub optNew_onclick()
        
         txtFirstName.Visible = True
         txtSurname.Visible = True
         txtComitID.Visible = False
         txtXXID.Visible = False
         txtBuilding.Visible = True
         txtTelephone.Visible = True
         txtDepartment.Visible = True
         txtEMail.Visible = True
         
    End Sub
    
    Private Sub optModify_onclick()
         
         txtFirstName.Visible = True
         txtSurname.Visible = True
         txtComitID.Visible = True
         txtXXID.Visible = True
         txtBuilding.Visible = False
         txtTelephone.Visible = False
         txtDepartment.Visible = False
         txtEMail.Visible = False
         
    End Sub
    

    Private Sub cmdClear_click()
    
         optNew.Value = Null
         optModify.Value = Null
         txtFirstName.Value = Null
         txtSurname.Value = Null
         txtComitID.Value = Null
         txtXXID.Value = Null
         txtBuilding.Value = Null
         txtTelephone.Value = Null
         txtDepartment.Value = Null
         txtEMail.Value = Null
         cboAccess.Value = Null
         chkMGI.Value = Null
         chkMGIOLD.Value = Null
         chkSLI.Value = Null
         chkSLIExpense.Value = Null
         chkCofL.Value = Null
    
    End Sub
    
    Private Sub cmdCancel_Click()
    
        Unload Me
        ActiveDocument.Close SaveChanges:=False
        
    End Sub

BUT ..... when I click new or mod nothing changes on the txt box side

Also the clear button, fill the option and check boxes and then greys them, rather than clearing them.

Any help will be greatly appreciated

MTIA

<Do I need A Signature or will an X do?>
 
Could just be the name of the sub being the problem

Easiest way to get to the Event of a control is to right click on it and choose "View Code"

If it creates a new sub when you do this, simply copy and paste the code out of your current sub into the new one - could be that the name of the control isn't Opt_New ?

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
To follow up on Geoff's post, it might be that the event is a Click event rather than onClick.

For the option buttons it would probably be better to set the values to false rather than null so you don't get the greying out effect.

Hope this helps

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Definately optNew .... didn't like optModify so changed it to optMod and it worked.

Also added in a visible = true for all txt boxes on the clear command, but it still greys the opt and chk :-(

<Do I need A Signature or will an X do?>
 
Setting the option and checkbox values to False rather than NULL will sort that out for you, e.g.
Code:
optNew.Value = False
         optModify.Value = False
         chkMGI.Value = False
         chkMGIOLD.Value = False
         chkSLI.Value = False
         chkSLIExpense.Value = False
         chkCofL.Value = False
Hope this helps

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
HarleyQuinn [cheers] again !!!!!

<Do I need A Signature or will an X do?>
 
Thanks [smile]

Glad to help [smile]

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Is there a way to ensure that one or other of the option boxes is checked and the relevant txt boxes filled in once the OK button clicked ???

<Do I need A Signature or will an X do?>
 
just check the value of the controls e.g.

if optnew = true then
if textbox1.text = "" then
msgbox "Please enter data into textbox1"
exit sub
end if
if textbox2.text = "" then
msgbox "Please enter data into textbox1"
exit sub
end if
'etc etc
'do data unload from form to document here
FormName.hide 'shuts down form


Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Cheers Geoff that has worked.

When I'm passing the data I'm using

Code:
With ActiveDocument
        .Bookmarks("First_Name").Range.Text = txtFirstName.Value

etc etc

and have put a screenupdating = false before them & a true after them, What can I do with check boxes ??

I.e. the optNew or optMod = true I would like a check box checked on the form .. can this be done ???


<Do I need A Signature or will an X do?>
 
Hey this is progressing! All the stuff you are working on here is the error trapping logic mentioned. How that is built depends on how much work you put into the logic. For example, in Geoff's code
Code:
if optnew = true then
   if textbox1.text = "" then
      msgbox "Please enter data into textbox1"
      [COLOR=red]exit sub[/color red]
   end if
   if textbox2.text = "" then
      msgbox "Please enter data into textbox1"
      [COLOR=red]exit sub[/color red]
   end if
suppose BOTH textbox1 and textbox2 are blank (""). The user clicks OK, and the logic checks if optnew = true. It is (let's assume). The code looks at textbox1, and if it is blanks displays the message about textbox1, and exits. Textbox2 (also blank) is not checked. The user clicks OK the second time, and NOW gets the error about textbox2. They have to go through the error trapping twice, they have to click OK three times - once to get the textbox1 error, second to get the textbox2 error and third time to finish.

There is nothing wrong with this, and is oftent done this way. This is where a lot of pain with this stuff lives. The more work you put in the error trapping, then the tighter the user interaction becomes. However, it DOES take more work, and it is up to you to determine how much work is warranted.

FormName.hide 'shuts down form

is not accurate. It does not shut down the form. "Unload Me" shuts down the form - if "shut down" means terminate. Hide does just that. It makes the form no longer visible. The form is still loaded.

Gerry
My paintings and sculpture
 
fumei

I think the users can put up with the pain (RSI's a b*&^h tho!!!!)

So far I have the following (With MANY MANY thanks to xlbo & HarleyQuin)

Code:
 Private Sub UserForm_Initialize()

         With cboAccess
         
        .AddItem "Input"
        .AddItem "Enquirer"
        .AddItem "Authoriser A"
        .AddItem "Authoriser B"
        .AddItem "Remove"
        .AddItem "Sysadmin"
        
        End With
    
    End Sub

    Private Sub optNew_click()
        
         txtFirstName.Visible = True
         lblFirstName.Visible = True
         txtSurname.Visible = True
         lblSurname.Visible = True
         txtComitID.Visible = True
         lblComitID.Visible = True
         txtXXID.Visible = False
         lblXX.Visible = False
         txtBuilding.Visible = True
         lblBuilding.Visible = True
         txtTelephone.Visible = True
         lblTelephone.Visible = True
         txtDepartment.Visible = True
         lblDept.Visible = True
         txtEMail.Visible = True
         lblEMail.Visible = True
         
    End Sub
    
    Private Sub optMod_click()
         
         txtFirstName.Visible = True
         lblFirstName.Visible = True
         txtSurname.Visible = True
         lblSurname.Visible = True
         txtComitID.Visible = True
         lblComitID.Visible = True
         txtXXID.Visible = True
         lblXX.Visible = True
         txtBuilding.Visible = False
         lblBuilding.Visible = False
         txtTelephone.Visible = False
         lblTelephone.Visible = False
         txtDepartment.Visible = False
         lblDept.Visible = False
         txtEMail.Visible = False
         lblEMail.Visible = False
         
    End Sub
    

    Private Sub cmdClear_click()
    
         txtFirstName.Visible = True
         lblFirstName.Visible = True
         txtSurname.Visible = True
         lblSurname.Visible = True
         txtComitID.Visible = True
         lblComitID.Visible = True
         txtXXID.Visible = True
         lblXX.Visible = True
         txtBuilding.Visible = True
         lblBuilding.Visible = True
         txtTelephone.Visible = True
         lblTelephone.Visible = True
         txtDepartment.Visible = True
         lblDept.Visible = True
         txtEMail.Visible = True
         lblEMail.Visible = True
         
         optNew.Value = False
         optMod.Value = False
         txtFirstName.Value = Null
         txtSurname.Value = Null
         txtComitID.Value = Null
         txtXXID.Value = Null
         txtBuilding.Value = Null
         txtTelephone.Value = Null
         txtDepartment.Value = Null
         txtEMail.Value = Null
         cboAccess.Value = Null
         chkMGI.Value = False
         chkMGIOLD.Value = False
         chkSLI.Value = False
         chkSLIExpense.Value = False
         chkCofL.Value = False
    
    End Sub
    
    Private Sub cmdCancel_Click()
    
        Unload Me
        ActiveDocument.Close SaveChanges:=False
        
    End Sub
    
    Private Sub cmdOK_Click()
    
                
        
        If optNew = True Then
        
            If txtFirstName.Text = "" Then
                MsgBox "Please enter your First Name"
                Exit Sub
            End If
            If txtSurname.Text = "" Then
                MsgBox "Please enter your Surname"
                Exit Sub
            End If
            If txtComitID.Text = "" Then
                MsgBox "Please enter your Comit ID"
                Exit Sub
            End If
            If txtBuilding.Text = "" Then
                MsgBox "Please enter which building you are in"
                Exit Sub
            End If
            If txtTelephone.Text = "" Then
                MsgBox "Please enter your Telephone Number"
                Exit Sub
            End If
            If txtDepartment.Text = "" Then
                MsgBox "Please enter which department you are in"
                Exit Sub
            End If
            If txtEMail.Text = "" Then
                MsgBox "Please enter your E-Mail Address"
                Exit Sub
            End If
            
        End If
        
        If optMod = True Then
        
            If txtFirstName.Text = "" Then
                MsgBox "Please enter your First Name"
                Exit Sub
            End If
            If txtSurname.Text = "" Then
                MsgBox "Please enter your Surname"
                Exit Sub
            End If
            If txtComitID.Text = "" Then
                MsgBox "Please enter your Comit ID"
                Exit Sub
            End If
            If txtXXID.Text = "" Then
                MsgBox "Please enter your XX Access ID"
                Exit Sub
            End If
                        
        End If
        
        If optNew = False And optMod = False Then
            MsgBox "Please choose either New User or Modify Access"
            Exit Sub
        End If
        
        
        
        Application.ScreenUpdating = False
        
        With ActiveDocument
        .Bookmarks("First_Name").Range.Text = txtFirstName.Value
        .Bookmarks("Surname").Range.Text = txtSurname.Value
        .Bookmarks("Comit_ID").Range.Text = txtComitID.Value
        .Bookmarks("Dept").Range.tetx = txtDepartment.Value
        .Bookmarks("XX_ID").Range.Text = txtXXID.Value
        .Bookmarks("Building").Range.Text = txtBuilding.Value
        .Bookmarks("Telephone").Range.Text = txtTelephone.Value
        .Bookmarks("Dept").Range.Text = txtDept.Value
        .Bookmarks("EMail").Range.Text = txtEMail.Value
        End With
        
        Application.ScreenUpdating = True
        
                
    End Sub

now all i need to do is pass the check boxes and then print it before closing it out.

<Do I need A Signature or will an X do?>
 
How about this?
Code:
With ActiveDocument
.CheckBox1_Doc.Value = CheckBox1_Form.Value 'the second checkbox being the one on your userform
You can include this in your current ActiveDocument With statement.

Hope this helps

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
pass the check boxes" ???

I generally agree with Gerry about the error trapping btw but I was just trying to give you some easy to understand examples.

Having said that, personally, I feel that users should accept a certain amount of responsibility for common sense and checking their work !!!

Anyway, good to see that you're nearly there. Printing should be easy, just hide / unload the form and use the print method of the document object

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
xlbo What i mean is if optNew on the user form is checked then a equivilent check box on the doc is checked

and use the print method of the document object
lost me after the and !!!!

HQ if I start .che i get check consistany, grammer & spelling no boxes :-(

<Do I need A Signature or will an X do?>
 
RCorrigan, it doesn't come up as an option on mine either (which is leading me to believe that I've not got the syntax in the way that Word wants, this is my first foray into Word VBA but I'm assuming the principles are the same as what I know) but if you type it in, it does capitalise it correctly when you leave the line and it worked fine on my machine here.

Cheers

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
yeh - if you can figure out how to reference the check box on the doc, all you need to do is set its value to TRUE or 1.

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Yeah, replace the names of the checkboxes that I used in the code above, you should be able to set your checkboxes to the values of the corresponding checkboxes on your userform [smile]

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Gone a diff way ...... declared a string and if the checkbox = true then it get inserted as data into the doc (instaed of a check box.

also get the printing too

it's not perfect so i may be back for more tips later !!!!

Thanks again

<Do I need A Signature or will an X do?>
 
If the checkbox in the document is a FormField (not an ActiveX control), and the names of them are, CheckNew, and CheckModify, then
Code:
ActiveDocument.FormFields("Check1").CheckBox.Value = True
or
Code:
ActiveDocument.FormFields("CheckNew").CheckBox.Value = CheckBox1_Form.Value
Obviously if you ARE using an ActiveX control checkbox, the code is different.


Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top