Can not get focus

  • Thread starter Thread starter Jean-Paul
  • Start date Start date
J

Jean-Paul

I wrote this code:

If [Forms]![verslagen].[Vragen]!Selectievakje15 = False Then
Me!teller = Me!teller - 1
If MsgBox("Opmerking?", vbOKOnly, "Let op!!") = vbOK Then
[Forms]![verslagen]![Vragen].Form!Selectievakje15 = True
[Forms]![verslagen]![Vragen].Form!Remarks_tekst.Visible = True
[Forms]![verslagen]![Vragen].Form!Bewaren.Enabled = True
[Forms]![verslagen]![Vragen].Form!Remarks.Visible = True
[Forms]![verslagen]![Vragen].Form!Remarks_tekst.Caption = "Opmerk:"
[Forms]![verslagen]![Vragen].Form!Remarks = ""
[Forms]![verslagen]![Vragen].Form!Remarks.SetFocus
End If
Else
[Forms]![verslagen].[Sub_Bedrijsgegevens].Visible = False
[Forms]![verslagen].[Vragen].Visible = False
[Forms]![verslagen].[Opdrachten].Visible = True
End If

I expect Remarks to get focus and the cursor is put into this entryfield.
But, not so
I get focus on the pushbutton that launches this code.

What am I doning wrong?
 
Vragen is a subform, correct? You need two SetFocus steps to set focus to a
control within a subform -- the first sets focus to the subform control, the
second sets focus to the control in that subform:

[Forms]![verslagen]![Vragen].SetFocus
[Forms]![verslagen]![Vragen].Form!Remarks.SetFocus
 
On Sat, 04 Oct 2008 20:10:23 +0200, Jean-Paul <[email protected]>
wrote:

Your first IF statement is probably wrong and should be:
If [Forms]![verslagen]![Vragen].Form!Selectievakje15 = False

You can probably replace all occurrences of "[Forms]![verslagen]" with
"Me". You can also use a With block to make your code more readable:
With Me!Vragen.Form
!Selectievakje15 = True
End With

Curious that you're testing a MsgBox with vbOKOnly for vbOK. You could
just write:
MsgBox "Opmerking?", vbOKOnly or vbExclamation, "Let op!!"
or since vbOKOnly is default:
MsgBox "Opmerking?", vbExclamation, "Let op!!"
(but I like to be explicit)

Setting focus to a control in a subform is a two-step process:
[Forms]![verslagen]![Vragen].SetFocus
[Forms]![verslagen]![Vragen].Form!Remarks.SetFocus
Or at least it used to be. I just tested this in A2007 (Northwind
Order Details form) and the first line can be omitted.

-Tom.
Microsoft Access MVP
 
Back
Top