Setfocus on a combo box from a subform

  • Thread starter Bill Fischer via AccessMonster.com
  • Start date
B

Bill Fischer via AccessMonster.com

I'm sure I must be missing something simple but I cannot set the focus on a
combo box on a main form control with an event from a subform control at
gotfocus. Run-time error '438': Object doesn't support this property or
method.

I have searched the threads and have nothing pertaining to an issue like this
(maybe just not entering correct key words). Have been trying to correct
this issue since last night and it is driving me over the edge.

My code on first control in subform checks for null or a default value in the
main form if the value is either of those a msgbox will tell user it must
have a value. Problem comes when I try to set focus to the main form control
combo box.

To check for proper language I set the combo box to a text box, then ran
event with same setfocus statement and it works perfectly. Is there a
different reference for a combo box or issue with source property I am not
using correctly? The source query field is a combo box and wondering may
that be the issue?

My code is:

Private Sub Invoice_Number_GotFocus()
If Not IsNull(Me.Parent![BUSINESS NAME]) Then
If Me.Parent!CodingID = 1137468902 Or IsNull(Me.Parent!CodingID) Then
MsgBox "You must enter a Category", vbInformation, "MISSING CATEGORY"

Me.Parent!CodingID.SetFocus

End If
End If

End Sub


Many thanks for any help.

Bill
 
D

Douglas J Steele

You haven't locked or disabled the control, have you?

I have no problem using that notation.
 
B

Bill Fischer via AccessMonster.com

Douglas thanks for the response, no neither locked or disabled. Did realize
thought that the name of the combo box was combobox6 instead of CodingID in
my coding. Clear minds in the morning will do wonders! Like I said something
probably simple.

Have another question though, how do I conditionally setfocus? I have added
another combo box to check for a value and would like to have focus on 1st
contol if both statements are true. As written now obviously focus will go
to 2nd combobox unless that statement is false.

Here is my code thus far:

Private Sub Invoice_Number_GotFocus()
If Not IsNull(Me.Parent![BUSINESS NAME]) Then
If Me.Parent!CodingID = 1137468902 Or IsNull(Me.Parent!CodingID) Then
MsgBox "You must enter a Category!", vbInformation, "MISSING CATEGORY"

Me.Parent!CodingID.SetFocus

End If
End If

If Not IsNull(Me.Parent![BUSINESS NAME]) Then
If Me.Parent!PayCodeID = 0 Or IsNull(Me.Parent!PayCodeID) Then
MsgBox "You must enter whether Eligible Yes/No!", vbInformation,
"MISSING ELIGIBLE"

Me.Parent!PayCodeID.SetFocus

End If
End If

End Sub


Thanks again your question got me looking at my combo settings and more
important the combo name.

Bill

You haven't locked or disabled the control, have you?

I have no problem using that notation.
I'm sure I must be missing something simple but I cannot set the focus on a
combo box on a main form control with an event from a subform control at
[quoted text clipped - 33 lines]
 
D

Douglas J Steele

What I typically do is have a text variable that I initialize to a
zero-length string ("")

As I go through the edits, I assign the name of the control where I want
focus to be set to that variable. If I always want focus set to the first
control I hit, I'll use something like:

If Len(strControlName) = 0 Then
strControlName = "NameOfControl"
End If

Then, once I've passed all the edit checks, I'll use:

If Len(strControlName) > 0 Then
Me.Controls(strControlName).SetFocus
End If

Now, this will obviously require tweaking in your Form/Subform setup, but
hopefully that gives you a direction...

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Bill Fischer via AccessMonster.com said:
Douglas thanks for the response, no neither locked or disabled. Did realize
thought that the name of the combo box was combobox6 instead of CodingID in
my coding. Clear minds in the morning will do wonders! Like I said something
probably simple.

Have another question though, how do I conditionally setfocus? I have added
another combo box to check for a value and would like to have focus on 1st
contol if both statements are true. As written now obviously focus will go
to 2nd combobox unless that statement is false.

Here is my code thus far:

Private Sub Invoice_Number_GotFocus()
If Not IsNull(Me.Parent![BUSINESS NAME]) Then
If Me.Parent!CodingID = 1137468902 Or IsNull(Me.Parent!CodingID) Then
MsgBox "You must enter a Category!", vbInformation, "MISSING CATEGORY"

Me.Parent!CodingID.SetFocus

End If
End If

If Not IsNull(Me.Parent![BUSINESS NAME]) Then
If Me.Parent!PayCodeID = 0 Or IsNull(Me.Parent!PayCodeID) Then
MsgBox "You must enter whether Eligible Yes/No!", vbInformation,
"MISSING ELIGIBLE"

Me.Parent!PayCodeID.SetFocus

End If
End If

End Sub


Thanks again your question got me looking at my combo settings and more
important the combo name.

Bill

You haven't locked or disabled the control, have you?

I have no problem using that notation.
I'm sure I must be missing something simple but I cannot set the focus on a
combo box on a main form control with an event from a subform control
at
[quoted text clipped - 33 lines]
 
B

Bill Fischer via AccessMonster.com

Great help Douglas, truly appreciate your time. Once I (as you said) got the
"tweaking" done everything works Marvelous! Simply Marvelous!

Thanks,

Bill
What I typically do is have a text variable that I initialize to a
zero-length string ("")

As I go through the edits, I assign the name of the control where I want
focus to be set to that variable. If I always want focus set to the first
control I hit, I'll use something like:

If Len(strControlName) = 0 Then
strControlName = "NameOfControl"
End If

Then, once I've passed all the edit checks, I'll use:

If Len(strControlName) > 0 Then
Me.Controls(strControlName).SetFocus
End If

Now, this will obviously require tweaking in your Form/Subform setup, but
hopefully that gives you a direction...
Douglas thanks for the response, no neither locked or disabled. Did realize
thought that the name of the combo box was combobox6 instead of CodingID in
[quoted text clipped - 44 lines]
 

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