setfocus

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I develop in access but was asked to put togther a questionaire in word.

I have added combo boxes to a document.

to add some validation checking I added;

If IsNull(cmdq1a) Or cmbq1a = "" Then
MsgBox "Please select a valid entry from question from 1A", vbCritical,
apptitle
Exit Sub
End If

in access i am able to include
cmbq1a.setfocus
after the msgbox entry to place the cursor/focus back to the relevant combox
box.

Word gives me a runtime error 438 object does not support this property ot
method.

How can I acheive this ? - cheers
 
Hi Paul,

Instead of SetFocus, the method name for a combo box from the Control
Toolbox is either Select or Activate (I'm not sure what the difference is,
if there is any).

If you just try to use cmbq1a.Select at that point in the macro, though, it
won't work. There's a timing bug, explained at
http://word.mvps.org/FAQs/TblsFldsFms/ValidateFFields.htm. This variation,
based on the code in the article, will work:

Private Sub cmbq1a_LostFocus()
If IsNull(cmbq1a) Or cmbq1a = "" Then
MsgBox "Please select a valid entry from question 1A", _
vbCritical, "Error"
Application.OnTime When:=Now + TimeValue("00:00:01"), _
Name:="GoThere"
End If
End Sub

Sub GoThere()
cmbq1a.Select
End Sub
 
Works a treat.

Thanks for your time

Paul

Jay Freedman said:
Hi Paul,

Instead of SetFocus, the method name for a combo box from the Control
Toolbox is either Select or Activate (I'm not sure what the difference is,
if there is any).

If you just try to use cmbq1a.Select at that point in the macro, though, it
won't work. There's a timing bug, explained at
http://word.mvps.org/FAQs/TblsFldsFms/ValidateFFields.htm. This variation,
based on the code in the article, will work:

Private Sub cmbq1a_LostFocus()
If IsNull(cmbq1a) Or cmbq1a = "" Then
MsgBox "Please select a valid entry from question 1A", _
vbCritical, "Error"
Application.OnTime When:=Now + TimeValue("00:00:01"), _
Name:="GoThere"
End If
End Sub

Sub GoThere()
cmbq1a.Select
End Sub
 
Back
Top