Really weird behaviour of textbox

A

Al

Hello folks,

I have a textbox that is behaving weird.

I created a form and after using it for a while had to make some changes.

The form has two Frames - Frame1 & Frame2. I moved Textbox10 from frame2 to
Frame1 and now for soem reason its not storing the variabe that I enter in
the userform. Hence when I click on the "OK" button it does not insert the
variable into the document. I have also put a line in that reads : msgbox
TextBox10 which confirms the variable is blank.

Interestingly I also have the following code;

Private Sub
TextBox10_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox10=StrConv(TextBox10, vbProperCase)
MsgBox TextBox10.Value
End Sub

Which stores the code just fine!! Its when I hit the OK button that the
variable is not stored and inserted into the document.

Does anyone know why? I have a funny feeling it is related to the change of
the Frames?

Cheers


-Al
 
P

Peter Hewett

Hi Al

A couple of things come to mind. The first is that some other code in your
form is nulling out yout TextBox control. The other is that your not
entering data into the control you think you are. Since you've posted a
very limited chunk of code it's difficult to tell.

Moving the TextBox from one frame to another should not affect the event
handling procedures as they're common to the form and not the frame.

The next stage is to insert some breakpoints in your code and checkout
what's really happening. If you always see the MsgBox after tabbing out of
the TextBox then you know it OK at that point. If that's the case then
check any other procedure that modifies the TextBox control. Add
breakpoints to the event handlers so that you can step through the code.
You can check objects/variable values using either the Immediate or Locals
window.

HTH + Cheers - Peter
 
A

Al

Hi Peter,

I have done what you suggested and discovered by process of elimination that
textbox10.value is stored until the following line of code;


' IF TEXTBOX1 NOT BLANK THEN ADD OFFENDER TO ARRAY

If TextBox1 <> "" Then

Call CommandButtonAddOffender_Click

End If


The procedure CommandButtonAddOffender_Click contains;

Public Sub CommandButtonAddOffender_Click()

With ListBox2

..ColumnCount = 10

..ColumnWidths = "100;0;0;0;0;0;0;0;0;0"

..BoundColumn = 1

..TextColumn = 1

End With

a = ListBox2.ListCount

ReDim Preserve OffenderArray(9, a)

OffenderArray(0, a) = TextBox1.Value & " " & TextBox2.Value 'Full Name

OffenderArray(1, a) = TextBox1.Value ' First Names

OffenderArray(2, a) = TextBox2.Value ' Family Name

OffenderArray(3, a) = TextBox3.Value ' DOB

OffenderArray(4, a) = TextBox4.Value ' Address

OffenderArray(5, a) = TextBox5.Value ' Age

OffenderArray(6, a) = TextBox6.Value ' Town

OffenderArray(7, a) = TextBox7.Value ' OCC

OffenderArray(8, a) = TextBox8.Value ' SID

OffenderArray(9, a) = TextBox9.Value ' PID

ListBox2.Column() = OffenderArray

Call ClearBoxes

End Sub

I think the problem lies in the fact that the value of TextBox10 is not
stored in the array and the second to last line is a procedure that clears
the contents of the text boxes?

-Al
 
P

Peter Hewett

Hi Al

A note for the future when creating Forms give the controls sensible names,
it makes the code immensely more comprehensible. E.g.: "TextBox3" which you
use for DOB could be named "txtDOB". You can change the names of controls
in the properties pane. Make sure you change the name as soon as you add
the control to the form. This way all the event handler procedures (Change,
Click, DblClick etc) have the correct name.

Standard control naming conventions use the following prefixes:
txt = TextBox
lbl = Label
cbo = ComboBox
lst = ListBox
chk = CheckBox
opt = OptionButton
tgl = ToggleButton
fra = Frame
cmd = CommandButton
btn = CommandButton (alternative to above)
tab = TabStrip
mpg = MultiPage
spn = SpinButton

Use one of the above prefixes (in lowercase) and then add the Name part.

I don't recommend that you change all the control names on your current
form as you will have to manually change all the control name references in
the Forms code.

HTH + Cheers - Peter
 
P

Peter Hewett

Hi Al

I can't tell for sure from the code you posted what's happening to
Textbox10. But as you say you're not storing it's value. You might
investigate whether you're clearing it in the "ClearBoxes" procedure.

Sorry this was supposed to be part of the last post but I lost the text!

HTH + Cheers - Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top