".SetFocus" on a form element and then having the combo box ".Dropdown"

C

CES

All,
I can't seem to get ".SetFocus" and ".Dropdown" to play nicely with one another.
I have a general function that Enables/Disables a Form Field. Which is called using the onExit Event Property (I've tried Lost Focus,Got Focus Events as well and that causes the same problem), of the Field Element.
The problem that I am running into is that I can't call the function prior to leaving the field because if I do,it will throw an error. So I need to SetFocus to the another field, prior to calling the function.
However, when I do that the dropDown property ceases to work properly, it drops down for a brief moment and then rolls back out.
If anyone has a clue as to how to get this to work properly, I would appreciate any advice or guidance. Thanks in advance.- CES

Fields list in Tab Order:
' ClientId - Combo
' DateOfInvoice - This field has been Disabled and Locked
' ApplyTo - Combo

Public Function fnEnableDisableTxtBox(controlName As String, actionToTake As String)
' Call fnEnableDisableTxtBox("NameOfTextBox", "Disable or Null")
' Will Change to opposite of Current State

Dim tmp As Control

Set tmp = Me.Controls(controlName)

If actionToTake <> "Disable" Then
tmp.Enabled = True
tmp.Locked = False
tmp.BackStyle = 1
Else
tmp.Enabled = False
tmp.Locked = True
tmp.BackStyle = 0
End If

End Function


Private Sub ClientId_Exit(Cancel As Integer)
If Me.DateOfInvoice.Value <> "" Then

'Me.DateOfInvoice.SetFocus - Will throw an error because it's already been Locked & Disabled
'Me.ApplyTo.Dropdown - Will throw an error, most likely because it doesn't have focus yet
'Me.ApplyTo.SetFocus - Will not throw an error, however the menu doesn't drop down properly
' it will only drop down for a brief moment and then it roll back up.
'Me.ApplyTo.Dropdown - Will not throw an error,

Call fnEnableDisableTxtBox("ClientId", "Disable")
End If
End Sub


Private Sub ApplyTo_Enter()
Me.ApplyTo.Dropdown
End Sub
 
C

CES

CES said:
All,
I can't seem to get ".SetFocus" and ".Dropdown" to play nicely with one
another.
I have a general function that Enables/Disables a Form Field. Which is
called using the onExit Event Property (I've tried Lost Focus,Got Focus
Events as well and that causes the same problem), of the Field Element.
The problem that I am running into is that I can't call the function
prior to leaving the field because if I do,it will throw an error. So I
need to SetFocus to the another field, prior to calling the function.
However, when I do that the dropDown property ceases to work properly,
it drops down for a brief moment and then rolls back out.
If anyone has a clue as to how to get this to work properly, I would
appreciate any advice or guidance. Thanks in advance.- CES

Fields list in Tab Order:
' ClientId - Combo
' DateOfInvoice - This field has been Disabled and Locked
' ApplyTo - Combo

Public Function fnEnableDisableTxtBox(controlName As String,
actionToTake As String)
' Call fnEnableDisableTxtBox("NameOfTextBox", "Disable or Null")
' Will Change to opposite of Current State

Dim tmp As Control

Set tmp = Me.Controls(controlName)

If actionToTake <> "Disable" Then
tmp.Enabled = True
tmp.Locked = False
tmp.BackStyle = 1
Else
tmp.Enabled = False
tmp.Locked = True
tmp.BackStyle = 0
End If

End Function


Private Sub ClientId_Exit(Cancel As Integer)
If Me.DateOfInvoice.Value <> "" Then

'Me.DateOfInvoice.SetFocus - Will throw an error because it's
already been Locked & Disabled
'Me.ApplyTo.Dropdown - Will throw an error, most likely because it
doesn't have focus yet
'Me.ApplyTo.SetFocus - Will not throw an error, however the menu
doesn't drop down properly
' it will only drop down for a brief moment and then it
roll back up.
'Me.ApplyTo.Dropdown - Will not throw an error,

Call fnEnableDisableTxtBox("ClientId", "Disable")
End If
End Sub


Private Sub ApplyTo_Enter()
Me.ApplyTo.Dropdown
End Sub

All,
Sorry for the premature post... SetFocus Was not causing the problem as I had thought, the problem was generated by one of the next two lines of code. Somehow they were drawing focus away from appliedTo.
changing the code as follows solved the problem. - CES

Private Sub ClientId_Exit(Cancel As Integer)
If Me.DateOfInvoice.Value <> "" Then
Me.ApplyTo.SetFocus
Me.InvoiceID.Value = fnSetInvoiceID(Me.ClientId.Value, Me.DateOfInvoice.Value)
Call fnEnableDisableTxtBox("ClientId", "Disable")
Me.ApplyTo.Dropdown

End If
End Sub
 
C

CES

CES said:
All,
Sorry for the premature post... SetFocus Was not causing the problem as
I had thought, the problem was generated by one of the next two lines of
code. Somehow they were drawing focus away from appliedTo.
changing the code as follows solved the problem. - CES

Private Sub ClientId_Exit(Cancel As Integer)
If Me.DateOfInvoice.Value <> "" Then
Me.ApplyTo.SetFocus
Me.InvoiceID.Value = fnSetInvoiceID(Me.ClientId.Value,
Me.DateOfInvoice.Value)
Call fnEnableDisableTxtBox("ClientId", "Disable")
Me.ApplyTo.Dropdown

End If
End Sub

Please reply to a newer posting (Still not working - ".SetFocus" on a form element and then having the combo box ".Dropdown")
 

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