Solved Problem with Rowsource in Combobox of Continuous Form. (1 Viewer)

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 07:14
Joined
Apr 1, 2019
Messages
731
Friends, So I have a combobox 'ContactPurpose' on a bound continuous subform. I wish to populate the combobox with all records except when the user enters a new record, in which case I wish to restrict their selection to only 'Active' records. So, i have 2 select queries as below on the Form_Current event. One rowsource displays all records & the other displays the 'active' records only. My problem is that upon entering a new record, the first entered record does not display it's contents until the user 'loses focus' on that record.

I hope I've made sense & someone can shed some light on my issue. Cheers.

Code:
Private Sub Form_Current()

Me.ContactPurpose.RowSourceType = "table/query"

If Me.NewRecord Then ' that is check that the rowsource record is active
    
    Me.ContactPurpose.RowSource = "SELECT ContactPurposeID, ContactPurpose, RelationshipTypeID " & _
    "FROM tluContactPurpose " & _
    "WHERE ((RelationshipTypeID)=[txtgroup]) AND (([Active(Y/N)])=Yes) " & _
   "ORDER BY ContactPurpose" '
    
                   'Me.ContactPurpose.Requery
          
    Else ' show every previously selected record
    Me.ContactPurpose.RowSource = "SELECT ContactPurposeID, ContactPurpose,RelationshipTypeID " & _
    "FROM tluContactPurpose " & _
    "WHERE ((RelationshipTypeID)=[txtgroup]) " & _
    "ORDER BY ContactPurpose"
    
     'Me.ContactPurpose.Requery
          
    End If
End Sub
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 13:14
Joined
Feb 28, 2001
Messages
27,188
You only have the requery in one leg (the ELSE leg) of your IF/THEN/ELSE fork yet you "diddle" with the .RowSource on both sides of the fork. I would expect awkward and apparently unsynchronized behavior in that situation.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:14
Joined
May 7, 2009
Messages
19,245
there is only 1 combobox on continuous form, so it will propagate to the rest of the record on the form.
what you need to do is add some dummy textbox and "overlay" it on top of the combobox, the source of the unbound textbox is the value of
ContactPurpose.
 

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 07:14
Joined
Apr 1, 2019
Messages
731
Gents, thanks for the prompt replies. I figured what @arnelgp deduced. @arnelgp do you know of a demo database that displays this technique? Appreciate your help as always.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:14
Joined
May 7, 2009
Messages
19,245
upload a db with tluContactPurpose on it then I will show you how or
just open the table, select all records, then copy/ paste to this screen so i see the content.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:14
Joined
May 7, 2009
Messages
19,245
..anyway here is a demo. open DemoForm.
"on top" of ContactPurposeID combobox is a dummy textbox (txtDummy). see its controlsource.
 

Attachments

  • comboOnContinuous.accdb
    800 KB · Views: 24

Babycat

Member
Local time
Tomorrow, 01:14
Joined
Mar 31, 2020
Messages
275
Just to fix Arnelgp's demo overlay issue. Bring txtDummy to forefront, set its background to normal (not transparent).
 

Attachments

  • 1.JPG
    1.JPG
    32.9 KB · Views: 15

Babycat

Member
Local time
Tomorrow, 01:14
Joined
Mar 31, 2020
Messages
275
..anyway here is a demo. open DemoForm.
"on top" of ContactPurposeID combobox is a dummy textbox (txtDummy). see its controlsource.
Hi Arnelgp

What if ContactPurpose combox's record source depends on selected value of Group?
i.e:
Group = A then ContactPurpose dropdown list = A1, A2, A3
Group = B then ContactPurpose dropdown list = B1, B2, B3, B4

Any idea please?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:14
Joined
May 7, 2009
Messages
19,245
BabyCat, you try again this demo.
 

Attachments

  • comboOnContinuous.accdb
    868 KB · Views: 25

Babycat

Member
Local time
Tomorrow, 01:14
Joined
Mar 31, 2020
Messages
275
Hi Arnelgp
It works great but for new record only.
If user changes Group of exising record, Subgroup does not filter out its rowsource.

1710670123086.png
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:14
Joined
May 7, 2009
Messages
19,245
that was the original request on post #1.
 

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 07:14
Joined
Apr 1, 2019
Messages
731
Gents, thanks for your input. Will have a go over the next couple of days & let you know how i get on.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:14
Joined
May 7, 2009
Messages
19,245
babyCat, this demo is for you.
 

Attachments

  • babyCombo.accdb
    868 KB · Views: 34

CJ_London

Super Moderator
Staff member
Local time
Today, 19:14
Joined
Feb 19, 2013
Messages
16,615
If user changes Group of exising record, Subgroup does not filter out its rowsource.

this sounds like what is called cascading combo's - see this link for an example


you need to use the combo enter/exit or got/lost focus events to modify the combo rowsource e.g.

Private Sub ContactPurpose_Enter()
If Me.NewRecord Then ' that is check that the rowsource record is active

Me.ContactPurpose.RowSource = "SELECT ContactPurposeID, ContactPurpose, RelationshipTypeID " & _
"FROM tluContactPurpose " & _
"WHERE ((RelationshipTypeID)=[txtgroup]) AND (([Active(Y/N)])=Yes) " & _
"ORDER BY ContactPurpose" '
end if

End Sub

Private Sub ContactPurpose_Exit()

If Me.NewRecord Then' show every previously selected record
Me.ContactPurpose.RowSource = "SELECT ContactPurposeID, ContactPurpose,RelationshipTypeID " & _
"FROM tluContactPurpose " & _
"WHERE ((RelationshipTypeID)=[txtgroup]) " & _
"ORDER BY ContactPurpose"

end if

end sub
 

Babycat

Member
Local time
Tomorrow, 01:14
Joined
Mar 31, 2020
Messages
275
Thank Arnelgp and CJ_London

The demo of Arnelgp works like a champ. That is what i have been looking for druing last 2 weeks. I stucked there, in fact I have to build a popup form instead of using cacading combo's.

CJ_London's demo is even better, I will study carefully. Very happy now, thank dudes!
 

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 07:14
Joined
Apr 1, 2019
Messages
731
@arnelgp , I downloaded your demo & yes, I can work with this. Exactly what I meant. A clever work around. Thanks a lot.
 

Users who are viewing this thread

Top Bottom