Trouble with SetFocus

TheB

Registered User.
Local time
Today, 16:57
Joined
Mar 17, 2003
Messages
25
Hi,

I have built a form for a report. I am in process of validating the fields on the form before generating my report. I have included a snippet of the code so you can see what I am trying to do.

If (txtIssue <> "") Then
sWhere = sWhere & " AND [AD_MAGAZINE_ISSUE] = " & txtIssue
End If
If (txtMagPage <> "") Then
sWhere = sWhere & " AND [AD_MAGAZINE_PAGE] = " & txtMagPage
End If
If (SalesRep <> "") Then
sWhere = sWhere & " AND [AD_MAGAZINE_SALESREP] = " & SalesRep
End If
If (BegSalesDate <> "" And IsNull(EndSalesDate)) Then
Forms!frmReportSelection!EndSalesDate.SetFocus
bOK = MsgBox("Enter value for end sales date.", vbOKOnly, "End Sales Date Error")
End If

Please take notice of the SetFocus command at the bottom of the snippet. It does not seem to be wroking for me. The form does not place focus in the EndSalesDate field. I do get the MsgBox but no focus to the specified field.

Can someone tell me what I am doing wrong here? I am very new to VB and I am still learning.

Also I also wonder where I should pass control once user does get focus and enters the EndSalesDate. I still would need to validate it. Would I use the Resume statement and pass control to a previous line? Maybe preceeding the BegSalesDate/EndSalesDate validation immediately.

Your help would be appreciated.

Thanks in advance.

...TheB
 
When is this code triggered? is the form you are validating the active form at the time? Is the form visible? Is the control enabled? If you are on the current form, why are you using the full form syntax instead of ME to refer to it? Where is the focus set when the validation is taking place?
 
AncientOne,

Here are my answers.

When is this code triggered? It is triggered on a preview report command button on form.

is the form you are validating the active form at the time? I believe so.

Is the form visible? Yes.

Is the control enabled? Yes, if you are referring to fiield I want to set focus to.

If you are on the current form, why are you using the full form syntax instead of ME to refer to it? I was not aware of this ME syntax. Can you give me an example of it?

Where is the focus set when the validation is taking place? Again the focus would have been on the Preview Report button as that is the last thing done before the Setfocus.

Hope my answers help.

Thanks for responding and for your help.

...TheB
 
1) put the SetFocus command AFTER the MsgBox.

2) Instead of Forms!frmReport...etc, just put Me!EndSalesDate.Set Focus. See Help under ME Keyword

3) Exit the Sub if there's no end date, but prompt the user to revalidate the form after the field is updated.

HTH
 
TheB,

I think that the form reference that you are
trying to make is:

Forms![YourMainForm]![frfmReportSelection]![EndSalesDate]

But as the Old Guy said, if your Report selection form
is the current form, you should just use Me.EndSalesDate.

The Preview Report button probably just brought up a
subform.

Wayne
 

Users who are viewing this thread

Back
Top Bottom