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

MaskEdBox question

Status
Not open for further replies.

shannanl

IS-IT--Management
Apr 24, 2003
1,071
US
I have a frame and a maskedbox on it. I set the mask of the box to ##:##. The user enters a time. I set the frames property to visible, true or false depending on if the user needs to enter the time. This can happen several times on a form. The first time the frame appears the maskedbox is blank. The second and thereafter it has the time that was entered the first time. I have tried the following to clear the maskedbox after the frame is made visible but it gives me an error. Here is my code:

'-- CUSTOM HOURS FRAME
Frame1.Visible = True
Frame1.ZOrder 0

'-- CLEAR THE MASKEDBOX
MaskEdBox1.Mask = ""
MaskEdBox1.Text = ""
MaskEdBox1.Mask = "##:##"

MaskEdBox1.SetFocus

The error is "invalid procedure call or argument" and its the setfocus that is causing the problem. Any suggestions on how to fix this. I need the set focus in there so the user is ready when the frame is made visible.

Thanks,

Shannan
 
Where are you placing this code I know you will get that error on the in the form load event because the maskedbox cannot have focus until the form is loaded.
 
This is a program to allow supervisors to schedule their employees. They drag their names from a list into either shift1, 2, or 3 list boxes. The name disappears from list 1 and appears in one of the 3 shift boxes and they are scheduled into a table in a database. The actual code is in the DragDrop event of one of the shift list boxes.

Shannan
 
The maskedbox is on a frame on the form.
 
Has the ENABLE property been set to 'False'?

What is the value of the CauseValidation property?
 
Enabled is set to true through the whole process. CauseValidation property is true.

Shannan
 
The only thing that I can think of that would cause that error is if the Frames visible or enabled properties are set to false at the time you are calling the setfocus method.
 
Check the CallStack during the DragDrop event.
The error might be caused by a different control.
 
I agree but as you can see from the code I am setting the frame to visible before the setfocus and to be sure I didnt have any stray code setting the enabled to false, I added enabled = true just before the set focus just to make sure and it still gives me the error. Im sure its something I am overlooking but I sure cant see it.

Thanks,

Shannan
 
Shannan

I dropped your code into a test form ... it works as expected. Setting the ENABLE property of Frame1 or MaskEdit1 to 'False' will raise the error.


Focus EVENTs occur in the following order:
Enter
GotFocus
Leave
Validating
Validaed
LostFocus

 
Im not sure how you got it to work. I tried the following and it still gives me the error:

'-- CUSTOM HOURS FRAME
Frame1.Visible = True
Frame1.ZOrder 0

'-- CLEAR THE MASKEDBOX
Frame1.Enabled = True
MaskEdBox1.Enabled = True
MaskEdBox1.Mask = ""
MaskEdBox1.Text = ""
MaskEdBox1.Mask = "##:##"

MaskEdBox1.SetFocus
 
If I take out the 3 lines that clear the maskedbox and leave the setfocus in there, it works fine. The frame apprears, the maskedbox1 has focus. Its ONLY when I add the three lines to clear it that it causes the set focus to throw the error.

Shannan
 
Option Explicit
Const lstNumericCharacters As String = ","

Dim firstname As String
Dim middlename As String
Dim lastname As String

Private Sub Form_Click()
Call Display_Clean_String
Call Display_AddressBook

'Will raise Error
Frame1.Enabled = False
Call Clear_MaskEdit

End Sub

'-----------------------------------
'--- Various testing procedures ---
'-----------------------------------

Private Sub Display_Clean_String()
'REQUIRE AN TextBox for numerical input.

Dim strDisplay As String
If Not IsNumeric(txtInput.Text) Then Exit Sub

strDisplay = Replace(Trim(txtInput.Text), lstNumericCharacters, "")
MsgBox strDisplay, vbInformation, "Numeric String Cleaned"
End Sub

Private Sub Display_AddressBook()
Dim strSplit() As String
Dim strStuff As String

strStuff = "John Q Public"
strSplit() = Split(strStuff, " ")
firstname = strSplit(0)
middlename = strSplit(1)
lastname = strSplit(2)

MsgBox lastname & ", " & firstname & " " & middlename, vbOKOnly, "Personal Address Book"

'**** FIRST CALL TO FRAME1 / MASKEDIT1 *****
Clear_MaskEdit
End Sub

Private Sub Clear_MaskEdit()

'-- CUSTOM HOURS FRAME
Frame1.Visible = True
Frame1.ZOrder 0

'-- CLEAR THE MASKEDBOX
MaskEdBox1.Mask = ""
MaskEdBox1.Text = ""
MaskEdBox1.Mask = "##:##"

MaskEdBox1.SetFocus


End Sub
 
Do you have any code in the change event of MaskEdBox1 that would set the frame visible to false, if so when you pass this line
MaskEdBox1.Text = ""
it fires the change event prior to
MaskEdBox1.SetFocus
just a though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top