PDA

View Full Version : VBA issue in WIN7



gowrisankar
08-24-2014, 10:07 AM
I have application called workdesk which has VBA editor tool in it for any modifications. We are migrating the application from XP to Win 7. We are facing a problem in the code after we moved the application to WIN7.

The problem is about focus on control.

We have a validation for each and every controls, if the validation fails, we throw error message and keep the focus on the same control to correct the error. If the validation passed then focus must be moved to next control.

The issue we are facing is whenever the validation is failed the message box pops up when we click ok, the focus is moving to the control but we can;t able to type-in in the control. we have to use to mouse to select the control then we have to type-in. I'm sure the focus is in that control but its not allowing us to type any character through keyboard unless we use mouse to select the control....

This piece of code worked fine in XP...but having issue over WIN7.

I use Cancel = true to keep the focus on the same control, I used this validation on File_Exit event.

hope you understand my problem....

Let me know if you need further details...

pls help : pray2:

Thanks in advance,
Gowrisankar

Bob Phillips
08-25-2014, 02:14 AM
I have win7, so can you post the workbook.

gowrisankar
08-25-2014, 03:42 AM
I have win7, so can you post the workbook.

Its a very big and lengthy code, I can't post the entier code here . But I'll post the part of the code that's troubling me.

Private Sub cmBrd.Exit(ByVal Cancel as MSForms.ReturnBoolean)
Set ActiveControl = cmbBrd

if Not CheckValues(cmbBrd.Text) then
Cancel = True
End if

End Sub

cmbBrd is a ComboBox with values(A,B,C,D)

The CheckValues() function will check the current value in the Combo Box with previous value, if it doesn;t match then it throws an error message letting user to select "Rekey/Overwrite"(allows user to correct value/indicate the entered value is correct), on selecting Rekey function will returns False and if user choose "Overwrite" return true allows focus to move to next control. If the value matches also the function will return true, the focus moves to next control.

Same check I perform for all the controls in the form.

To make the control available for entrying values I have tried

cmbBRD.SelText = cmbBRD.Text but no luck...can't able to type in the values in the control without using mosue.


One thing I noticed is that key press event working in that control. I have created keypress event for the control. After the validation fails and focus set back to the control when I press any key they keypress event is firing...but words/letters not getting printed in the control...

Regards,
Gowrisankar

ranman256
08-25-2014, 06:48 AM
I get nothing but headaches when I use .Exit and cancel = true methods.
Remove that code checking and just do a IsValidForm() that checks all controls.
Then either save and close or not.



public Function IsValidForm() as boolean
dim vMsg
select case true
case txtName = ""
vMsg = "Name is missing"
case cboState= ""
vMsg = "State is missing"
cboState.setfocus
end select
if vMsg <>"" then msgbox vmsg,vbCritical,"Required"
IsValidForm =vMsg =""
end sub

gowrisankar
08-25-2014, 07:10 AM
Thanks ranman256.

But I want to check the validation on existing from the control.

If we dont use the Cancel = True the focus will go to next control.

How to set it in the same control without using Cancel= True?

ranman256
08-25-2014, 09:44 AM
Like I said, when they click 'SAVE', it runs the IsValid and checks all controls there and if 1 is wrong, sets the focus.
When all is correct, IsValid = true and the 'save' is executed.

1 piece of code rather than code inside every control.

gowrisankar
08-25-2014, 10:39 AM
Like I said, when they click 'SAVE', it runs the IsValid and checks all controls there and if 1 is wrong, sets the focus.
When all is correct, IsValid = true and the 'save' is executed.

1 piece of code rather than code inside every control.


Thanks for the suggestion...but i need to check on each and every control while exiting....like if the name is matched then i have to allow to check next details....

this is an old application...and users may not accept what you suggested...its a big change in the process flow.

any other suggestions???

BrynjulfRasm
09-16-2015, 05:37 AM
How do you solve this question?