Help sought re vbmodeless form rendering a class module useless

T

The Clint

Hey guys,

Here is my problem:

I have a form which has a button on it that when clicked, changes the form
from modal to modeless - the reason for this is so people can then go to
excel and copy and paste list of numbers into the form from a sheet they may
have been emailed.

The problem is that the form being modeless then renders class modules I
have useless.

The class modules are there so certain buttons and text boxes do the same
things.

In terms of my text boxes, the class module detects somebody has hit enter
then makes the frame below it visible and ready for inputing more.

This works perfectly until I make the form modeless - is there a reason for
this and is there a way to kick the damn thing into working order?

I tried the repaint option, thinking that a sokution to a modeless
displayscreen problem i had may work but it didn't do the trick in this
case.

Thank you in advance for your help.

Clint
 
N

Norman Jones

Hi Clint,

'-----------------
I have a form which has a button on it that when clicked, changes the form
from modal to modeless - the reason for this is so people can then go to
excel and copy and paste list of numbers into the form from a sheet they may
have been emailed.

The problem is that the form being modeless then renders class modules I
have useless.

The class modules are there so certain buttons and text boxes do the same
things.

In terms of my text boxes, the class module detects somebody has hit enter
then makes the frame below it visible and ready for inputing more.

This works perfectly until I make the form modeless - is there a reason for
this and is there a way to kick the damn thing into working order?

I tried the repaint option, thinking that a sokution to a modeless
displayscreen problem i had may work but it didn't do the trick in this
case.
'-----------------

It would be useful if you were to post your button code. I
would have anticipated a run time error.

As a matter of interest, why seek to change the display
mode? Why do you not simply display the userform non
modally?
 
T

The Clint

Hi Norman,

The reason I change the display mode is so as to allow excel to be accessed
by the user so they can view their spreadsheet then copy values from it then
they can paste it into the userform running.

My code revolving around the class module that is impacted is as follows:

Private Sub Workbook_open()
Dim Buttons() As New Class1
Dim Boxes() As New Class2
Dim Checks() As New Class3

Dim ctl As Control

ButtonCount = 0
BoxCount = 0
CheckCount = 0
For Each ctl In UserForm4.Controls
If TypeName(ctl) = "TextBox" Then
BoxCount = BoxCount + 1
ReDim Preserve Boxes(1 To BoxCount)
Set Boxes(BoxCount).TBGroup = ctl
End If

If TypeName(ctl) = "CommandButton" Then
If ctl.Name <> "OKButton" Then 'Skip the OKButton
ButtonCount = ButtonCount + 1
ReDim Preserve Buttons(1 To ButtonCount)
Set Buttons(ButtonCount).ButtonGroup = ctl
End If
End If

If TypeName(ctl) = "CheckBox" Then
CheckCount = CheckCount + 1
ReDim Preserve Checks(1 To CheckCount)
Set Checks(CheckCount).CBGroup = ctl
End If

Next ctl

Call Initial_setup

End Sub



and the actual class module....

Public WithEvents TBGroup As MSFOrms.TextBox

Private Sub TBGroup_change()

Namby = Right(TBGroup.Name, Len(TBGroup.Name) - 7)

If Right(UserForm4.Controls(TBGroup.Name).Value, 1) = Chr(32) Then
UserForm4.Controls(TBGroup.Name).Value =
Left(UserForm4.Controls(TBGroup.Name).Value,
Len(UserForm4.Controls(TBGroup.Name).Value) - 1)

If Right(UserForm4.Controls(TBGroup.Name).Value, 1) = Chr(10) Or
Right(UserForm4.Controls(TBGroup.Name).Value, 1) = Chr(13) Then
If Val(Namby) <= 70 Then
If Int(((Val(Namby) - 1) / 3)) = ((Val(Namby) - 1) / 3) Then
TempPhrase = UCase(UserForm4.Controls(TBGroup.Name).Value)
For Strip = 1 To Len(TempPhrase)
If Asc(Mid(TempPhrase, Strip, 1)) > 41 Then Phrase =
Phrase + Mid(TempPhrase, Strip, 1)
Next Strip
UserForm4.Controls(TBGroup.Name).Value = Phrase
Phrase = ""
If UserForm4.Controls("Frame" & (((Val(Namby) + 2) / 3) +
1)).Visible = False Then
UserForm4.Controls("Frame" & (((Val(Namby) + 2) / 3) +
1)).Visible = True
UserForm4.Controls("Label" & (25 + (((Val(Namby) + 2) /
3) + 1))).Visible = True
End If
UserForm4.Controls("TextBox" & (Val(Namby) + 3)).SetFocus
End If
End If
End If

End Sub



What appears to happen when i change it to modeess is that the enter key
does not seem to be recognised any more and where the above should stop a
carriage return and strip it out of what was entered then go to a new line,
it seems to do a soft enter.

So in effect the event trapping for detecting chr(10) is not working any
longer once it is modeless.

As far as I know there is no different between non modal and modeless or are
they actually different?

Thanks for your help.

Clint
 
N

Norman Jones

Hi Clint,

I still do not understand why you do not display the Userform
modelessly.

The code that I woululd like to have seen posted is the userform
button code to change the display mode.


---
Regards,
Norman




The Clint said:
Hi Norman,

The reason I change the display mode is so as to allow excel to be
accessed by the user so they can view their spreadsheet then copy values
from it then they can paste it into the userform running.

My code revolving around the class module that is impacted is as follows:

Private Sub Workbook_open()
Dim Buttons() As New Class1
Dim Boxes() As New Class2
Dim Checks() As New Class3

Dim ctl As Control

ButtonCount = 0
BoxCount = 0
CheckCount = 0
For Each ctl In UserForm4.Controls
If TypeName(ctl) = "TextBox" Then
BoxCount = BoxCount + 1
ReDim Preserve Boxes(1 To BoxCount)
Set Boxes(BoxCount).TBGroup = ctl
End If

If TypeName(ctl) = "CommandButton" Then
If ctl.Name <> "OKButton" Then 'Skip the OKButton
ButtonCount = ButtonCount + 1
ReDim Preserve Buttons(1 To ButtonCount)
Set Buttons(ButtonCount).ButtonGroup = ctl
End If
End If

If TypeName(ctl) = "CheckBox" Then
CheckCount = CheckCount + 1
ReDim Preserve Checks(1 To CheckCount)
Set Checks(CheckCount).CBGroup = ctl
End If

Next ctl

Call Initial_setup

End Sub



and the actual class module....

Public WithEvents TBGroup As MSFOrms.TextBox

Private Sub TBGroup_change()

Namby = Right(TBGroup.Name, Len(TBGroup.Name) - 7)

If Right(UserForm4.Controls(TBGroup.Name).Value, 1) = Chr(32) Then
UserForm4.Controls(TBGroup.Name).Value =
Left(UserForm4.Controls(TBGroup.Name).Value,
Len(UserForm4.Controls(TBGroup.Name).Value) - 1)

If Right(UserForm4.Controls(TBGroup.Name).Value, 1) = Chr(10) Or
Right(UserForm4.Controls(TBGroup.Name).Value, 1) = Chr(13) Then
If Val(Namby) <= 70 Then
If Int(((Val(Namby) - 1) / 3)) = ((Val(Namby) - 1) / 3) Then
TempPhrase = UCase(UserForm4.Controls(TBGroup.Name).Value)
For Strip = 1 To Len(TempPhrase)
If Asc(Mid(TempPhrase, Strip, 1)) > 41 Then Phrase =
Phrase + Mid(TempPhrase, Strip, 1)
Next Strip
UserForm4.Controls(TBGroup.Name).Value = Phrase
Phrase = ""
If UserForm4.Controls("Frame" & (((Val(Namby) + 2) / 3) +
1)).Visible = False Then
UserForm4.Controls("Frame" & (((Val(Namby) + 2) / 3) +
1)).Visible = True
UserForm4.Controls("Label" & (25 + (((Val(Namby) + 2) /
3) + 1))).Visible = True
End If
UserForm4.Controls("TextBox" & (Val(Namby) + 3)).SetFocus
End If
End If
End If

End Sub



What appears to happen when i change it to modeess is that the enter key
does not seem to be recognised any more and where the above should stop a
carriage return and strip it out of what was entered then go to a new
line, it seems to do a soft enter.

So in effect the event trapping for detecting chr(10) is not working any
longer once it is modeless.

As far as I know there is no different between non modal and modeless or
are they actually different?

Thanks for your help.

Clint
 
T

The Clint

I am displaying it modelessly, which is what is causing the problem with the
class module. The code for the button is as follows:


Private Sub ModeChange_Click()
UserForm4.Hide
UserForm4.Show vbModeless
End Sub

Regards,
Clint


Norman Jones said:
Hi Clint,

I still do not understand why you do not display the Userform
modelessly.

The code that I woululd like to have seen posted is the userform
button code to change the display mode.
 
N

Norman Jones

Hi Clint,
I am displaying it modelessly, which is what is causing the problem with
the class module. The code for the button is as follows:


Private Sub ModeChange_Click()
UserForm4.Hide
UserForm4.Show vbModeless
End Sub

No, I meant display the Userform modelessly when you first call it!

In other words, *never* show it modally.
 
T

The Clint

I just made it show it modeless from itsfirst call up and the problem still
occurs.

maybe it's just not meant to work.

Thanks anyway for the help.

Regards,
Clint
 
N

Norman Jones

Hi Clint,

Did you try running the Workbook_Open procedure beefore loading the
Userform?
 
P

Peter T

maybe it's just not meant to work.

It can't work in the way you do it!

Referring to an earlier post, when you do the .Hide in the form, code passes
back to the procedure (workbook_open) that Show'd the form and runs to the
end. The ref's to your withevents classes, stored in that procedure, go out
of scope destroying your classes.

You could maintain the ref's either at global level or the normal way at
module level in the form. So, instead create your classes in the form's
initialze event.

Even with this change it's an odd setup!

Regards,
Peter T
 
T

The Clint

Norman,

I did try the WorkBook Open procedure as per the normal way of operation for
the app. The modeless just seems to make it ignore the class modules.

I inserted a 'msgbox "hi"' into the class module so when i entered any key
at all into the textbox it should have said Hi... this did not occur.

Once again thanks for the help.

Cheers,
Clint
 
N

Norman Jones

Hi Clint,

I had not looked at your code, instead concentarting
on your desire to change the display mode of the
userform.

However, I note that Peter has posted pertinent
commnts on your code in an adjacent post.
 
T

The Clint

Thanks for the reply Peter.

I thought the events were public but i realise what you were saying now. I
have re-applied it now and it works!!

Thank you.

Regards,
Clint
 

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