Can not get focus

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?
 
K

Ken Snell \(MVP\)

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
 
T

Tom van Stiphout

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
 

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