PDA

View Full Version : Solved: Text box



chungtinhlak
12-10-2008, 11:42 AM
I have a form with 18 different textboxes, at initialize, these textbox have a default value in them. i ahve a clear button to clear all these but some how when i hit find, all the default date form initializing stage of the form still is the value of my textbox, all the keyword that i entered are not being taken. Can someone help me.

thanks


Private Sub cmdcancel_Click()
Unload Me
End Sub
Private Sub cmdclear_Click()
keywordlookup.TextBox1.Value = ""
keywordlookup.TextBox2.Value = ""
keywordlookup.TextBox3.Value = ""
keywordlookup.TextBox4.Value = ""
keywordlookup.TextBox5.Value = ""
keywordlookup.TextBox6.Value = ""
keywordlookup.TextBox7.Value = ""
keywordlookup.TextBox8.Value = ""
keywordlookup.TextBox9.Value = ""
keywordlookup.TextBox10.Value = ""
keywordlookup.TextBox11.Value = ""
keywordlookup.TextBox12.Value = ""
keywordlookup.TextBox13.Value = ""
keywordlookup.TextBox14.Value = ""
keywordlookup.TextBox15.Value = ""
keywordlookup.TextBox16.Value = ""
keywordlookup.TextBox17.Value = ""
keywordlookup.TextBox18.Value = ""
End Sub
Private Sub cmdfind_Click()
Unload Me
If keywordlookup.TextBox1.Value = "" Then
keywordlookup.TextBox1.Value = "No Keyword To Search"
End If
If keywordlookup.TextBox2.Value = "" Then
keywordlookup.TextBox2.Value = "No Keyword To Search"
End If
If keywordlookup.TextBox3.Value = "" Then
keywordlookup.TextBox3.Value = "No Keyword To Search"
End If
If keywordlookup.TextBox4.Value = "" Then
keywordlookup.TextBox4.Value = "No Keyword To Search"
End If
If keywordlookup.TextBox5.Value = "" Then
keywordlookup.TextBox5.Value = "No Keyword To Search"
End If
If keywordlookup.TextBox6.Value = "" Then
keywordlookup.TextBox6.Value = "No Keyword To Search"
End If
If keywordlookup.TextBox7.Value = "" Then
keywordlookup.TextBox7.Value = "No Keyword To Search"
End If
If keywordlookup.TextBox8.Value = "" Then
keywordlookup.TextBox8.Value = "No Keyword To Search"
End If
If keywordlookup.TextBox9.Value = "" Then
keywordlookup.TextBox9.Value = "No Keyword To Search"
End If
If keywordlookup.TextBox10.Value = "" Then
keywordlookup.TextBox10.Value = "No Keyword To Search"
End If
If keywordlookup.TextBox11.Value = "" Then
keywordlookup.TextBox11.Value = "No Keyword To Search"
End If
If keywordlookup.TextBox12.Value = "" Then
keywordlookup.TextBox12.Value = "No Keyword To Search"
End If
If keywordlookup.TextBox13.Value = "" Then
keywordlookup.TextBox13.Value = "No Keyword To Search"
End If
If keywordlookup.TextBox14.Value = "" Then
keywordlookup.TextBox14.Value = "No Keyword To Search"
End If
If keywordlookup.TextBox15.Value = "" Then
keywordlookup.TextBox15.Value = "No Keyword To Search"
End If
If keywordlookup.TextBox16.Value = "" Then
keywordlookup.TextBox16.Value = "No Keyword To Search"
End If
If keywordlookup.TextBox17.Value = "" Then
keywordlookup.TextBox17.Value = "No Keyword To Search"
End If
If keywordlookup.TextBox18.Value = "" Then
keywordlookup.TextBox18.Value = "No Keyword To Search"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''
'''''''''''''''''''''''''''''
Range("AT:BN").Select
Selection.ClearContents
''''''''''''''''''''''''''''
Range("AW1").Select
ActiveCell.FormulaR1C1 = keywordlookup.TextBox1
Range("AX1").Select
ActiveCell.FormulaR1C1 = keywordlookup.TextBox2
Range("AY1").Select
ActiveCell.FormulaR1C1 = keywordlookup.TextBox3
Range("AZ1").Select
ActiveCell.FormulaR1C1 = keywordlookup.TextBox4
Range("BA1").Select
ActiveCell.FormulaR1C1 = keywordlookup.TextBox5
Range("BB1").Select
ActiveCell.FormulaR1C1 = keywordlookup.TextBox6
Range("BC1").Select
ActiveCell.FormulaR1C1 = keywordlookup.TextBox7
Range("BD1").Select
ActiveCell.FormulaR1C1 = keywordlookup.TextBox8
Range("BE1").Select
ActiveCell.FormulaR1C1 = keywordlookup.TextBox9
Range("BF1").Select
ActiveCell.FormulaR1C1 = keywordlookup.TextBox10
Range("BG1").Select
ActiveCell.FormulaR1C1 = keywordlookup.TextBox11
Range("BH1").Select
ActiveCell.FormulaR1C1 = keywordlookup.TextBox12
Range("BI1").Select
ActiveCell.FormulaR1C1 = keywordlookup.TextBox13
Range("BJ1").Select
ActiveCell.FormulaR1C1 = keywordlookup.TextBox14
Range("BK1").Select
ActiveCell.FormulaR1C1 = keywordlookup.TextBox15
Range("BL1").Select
ActiveCell.FormulaR1C1 = keywordlookup.TextBox16
Range("BM1").Select
ActiveCell.FormulaR1C1 = keywordlookup.TextBox17
Range("BN1").Select
ActiveCell.FormulaR1C1 = keywordlookup.TextBox18
Application.Run "workbook_setup"
Application.Run "Keyword_lookup"

End If


End Sub



Private Sub UserForm_Initialize()
keywordlookup.TextBox1.Value = "epd written"
keywordlookup.TextBox2.Value = "epd required"
keywordlookup.TextBox3.Value = "Need epd"
keywordlookup.TextBox4.Value = "required epd"
keywordlookup.TextBox5.Value = "epd needed"
keywordlookup.TextBox6.Value = "epd need"
keywordlookup.TextBox7.Value = "epd request"
keywordlookup.TextBox8.Value = "request epd"
keywordlookup.TextBox9.Value = "needs epd"
keywordlookup.TextBox10.Value = "need rev"
keywordlookup.TextBox11.Value = "epd for"
keywordlookup.TextBox12.Value = "EPD Initiation"
keywordlookup.TextBox13.Value = "EPD initiated"
keywordlookup.TextBox14.Value = "to initiated"
keywordlookup.TextBox15.Value = "please initiate"
keywordlookup.TextBox16.Value = "initiate epd"
keywordlookup.TextBox17.Value = "initiate pick-up"
keywordlookup.TextBox18.Value = ""

End Sub

mdmackillop
12-10-2008, 11:53 AM
Can you post your workbook?

Cosmo
12-10-2008, 11:58 AM
IT looks to me like you've included all of the code you want to run into the 'If' statement for TextBox18. If that's empty, it won't run.

mdmackillop
12-10-2008, 12:15 PM
IT looks to me like you've included all of the code you want to run into the 'If' statement for TextBox18. If that's empty, it won't run.
Well spotted!

The code can be condensed a bit too


Private Sub cmdcancel_Click()
Unload Me
End Sub

Private Sub cmdclear_Click()
For i = 1 To 18
Me.Controls("TextBox" & i).Value = ""
Next
End Sub

Private Sub cmdfind_Click()
Unload Me
For i = 1 To 18
If Me.Controls("TextBox" & i).Value = "" Then
Me.Controls("TextBox" & i).Value = "No Keyword To Search"
End If
Next

Range("AT:BN").ClearContents

For i = 1 To 18
Range("AV1").Offset(, i) = Me.Controls("TextBox" & i).Value
Next

Application.Run "workbook_setup"
Application.Run "Keyword_lookup"

End Sub

Private Sub UserForm_Initialize()
With keywordlookup
.TextBox1.Value = "epd written"
.TextBox2.Value = "epd required"
.TextBox3.Value = "Need epd"
.TextBox4.Value = "required epd"
.TextBox5.Value = "epd needed"
.TextBox6.Value = "epd need"
.TextBox7.Value = "epd request"
.TextBox8.Value = "request epd"
.TextBox9.Value = "needs epd"
.TextBox10.Value = "need rev"
.TextBox11.Value = "epd for"
.TextBox12.Value = "EPD Initiation"
.TextBox13.Value = "EPD initiated"
.TextBox14.Value = "to initiated"
.TextBox15.Value = "please initiate"
.TextBox16.Value = "initiate epd"
.TextBox17.Value = "initiate pick-up"
.TextBox18.Value = ""
End With
End Sub

Bob Phillips
12-10-2008, 12:16 PM
Also, if you unload it as the first action in cmdfind, nothing else happens does it?

chungtinhlak
12-10-2008, 12:58 PM
sorry guy, the workbook is over 50mb,

XLD, it just unload the form but everything else runs.

I guess my question is how come when I clear (clear button) all the entries from start up. Input my own keyword in, click find, the text that I input doesn't goes into the appropriete field but the text that I cleared (from start up) does.

chungtinhlak
12-10-2008, 12:59 PM
MXMack, what does Next do?

mdmackillop
12-10-2008, 01:13 PM
Try stepping though the code.

chungtinhlak
12-10-2008, 01:43 PM
xld,

you're right, unload me from the beginning resets everything that you do and set it back to the default stage of the form. thanks

mdmack,

thanks for you help, i really like your code, it's so clean,

can you hlep me explain this part of your code,

Range("AT:BN").ClearContents

For i = 1 To 18
Range("AV1").Offset(, i) = Me.Controls("TextBox" & i).Value
Next

mdmackillop
12-10-2008, 01:49 PM
It writes the value from each textbox in turn into successive cells across the sheet. Did you try stepping through?

BTW,
I agree Unload should be placed at the end of the code, but unexpectedly, it works as is.

chungtinhlak
12-10-2008, 07:37 PM
how do you do a step through?

Bob Phillips
12-11-2008, 01:24 AM
There is a debug toolbar in the VBIDE, one of the buttons allows you to set a breakpointm, and when your code stops other buttons allow you to step through the next lines.