PDA

View Full Version : Text Boxes visible not visible on user form



austenr
11-06-2017, 09:59 AM
Trying to make the label and text box visible in the second sub. Code works when the initialize sub runs but not when you are checking the check box in the second sub.


Private Sub UserForm_Initialize()
UserForm1.lblAcctsPayable.Visible = False
UserForm1.lblPrimaryAdmin.Visible = False
UserForm1.txtAcctsPayable.Visible = False
UserForm1.txtPrimaryAdmin.Visible = False
UserForm1.txtAcctNum.BackColor = RGB(255, 255, 0)
UserForm1.txtAcctName.BackColor = RGB(255, 255, 0)
UserForm1.txtOrderNum.BackColor = RGB(255, 255, 0)
End Sub


Sub TextBoxCheck()
If UserForm1.chkAdmin = True Then
UserForm1.lblPrimaryAdmin.Visible = True
UserForm1.txtPrimaryAdmin.Visible = True

End If

End Sub

p45cal
11-06-2017, 10:41 AM
Supply file with this setup in it.

Kenneth Hobs
11-06-2017, 10:47 AM
Something else is going on I guess, ergo the request for a file or more code.

Normally, I set static default property values at design time rather than run time in Initialize event.

Is Userform1 the current userform? If so, it is not needed.


'Set as defaults at design time normally.
Private Sub UserForm_Initialize()
Label1.Visible = False
TextBox1.Visible = False
End Sub

Private Sub CheckBox1_Click()
'Not .visible=.visible normally used rather than IF/ELSE.
If CheckBox1.Value = True Then
Label1.Visible = True
TextBox1.Visible = True
Else
Label1.Visible = False
TextBox1.Visible = False
End If
End Sub

austenr
11-06-2017, 10:55 AM
Sorry guys thought is was just an oversight. In the attached I have two check boxes on the user form and depending on what box is checked the caption on the label would need to be displayed. Anyway, here is the WB. Thanks.

Also if there is a better way to do it I am all for that.

Paul_Hossler
11-06-2017, 11:06 AM
I'm thinking you want to handle the CB change event




Private Sub chkAdmin_change()
With UserForm1
.lblPrimaryAdmin.Visible = .chkAdmin.Value
.txtPrimaryAdmin.Visible = .chkAdmin.Value
End With
End Sub



This doesn't seen to be called anywhere



Sub TextBoxCheck()
If UserForm1.chkAdmin = True Then
UserForm1.lblPrimaryAdmin.Visible = True
UserForm1.txtPrimaryAdmin.Visible = True

End If

End Sub


BTW, unsolicited suggestion: I'd add [Update] and [Cancel] command buttons to the form

austenr
11-06-2017, 11:23 AM
thanks Paul. makes sense. something else i was wondering, on the form if there an efficient way to clear the First name, Middle Name, text boxes with a button. And the last thing i cant find it anywhere on the web so far:


Is there a way to copy the text boxes with names, addresses, etc. and paste them in a format that keeps them from running together in one string? So if yo paste it into something like notepad you would get:

Dave
M
Jones
999-111-1111

etc.

Thanks.

Kenneth Hobs
11-06-2017, 12:16 PM
It is best to start a new topic thread for new topics.

String concatenation is how it is done. e.g.
1.

s = Textbox1.Value & vbCrLf & Textbox2.Value
2.
Dim a(1 to 2), s
a(1) = TextBox1.Value
a(2) = TextBox2.Value
s = Join(a, vbCrLF)


If all TextBox controls, you could fill an array. The Tag property could be set to the order that you want the values in the array. Of course another iteration of the array would be needed once the Tag order was sorted. You would probably want to skip filling the array if a Value = "".

For a few string concatenations, method (1) would suffice. For many, method (2) is best.

austenr
11-06-2017, 03:46 PM
Hi Kenneth.

I tried your code to copy as follows but it doesnt paste it to anything?


Private Sub CommandButton1_Click()'copies data to clip board for paste to BITS
Dim a(1 To 2), s
a(1) = UserForm1.txtFName.Value
a(2) = UserForm1.txtLName.Value
s = Join(a, vbCrLf)


End Sub

Kenneth Hobs
11-06-2017, 04:29 PM
There are several ways to write the data. Did you really want to paste? Is the file open? What kind of file: Word, txt, Excel, Outlook, etc.? Does the file exist? I guess it is a txt file as you said paste to Notepad.

It is always faster to work in the background rather than foreground when you can.

austenr
11-06-2017, 04:57 PM
Would like to write it vertically to A1 sheet 1. The form is for data entry so people will not make mistakes and put it in what we have now which is a plain old excel spreadsheet. After the data is entered in the form ideally i would like to write the labels and text boxes to sheet 1 as they appear on the user form. I know it seems like double work and it sort of is but it controls what people put when and where. Hope that makes sense.

Kenneth Hobs
11-06-2017, 05:09 PM
Sub Test()
Dim a(1 To 2, 1 To 1)
a(1, 1) = "My name is:"
a(2, 1) = "Kenneth Hobson"
'[A1].Resize(UBound(a, 1)).Value = a
[A1].Resize(UBound(a)).Value = a
End Sub