S
sturose2000
I've found snippets of help in other posts and in Help files, but still
can't get this to work nicely:
I have a form frmContacts, that contains an unbound combo box cboUniv and a
bound combo box cboOrganization. The cboUniv is just to make the choices
"pretty," viz., each record in tblContacts has an Organization; the
Organization may be a University or may have an Affiliation with a
University. Thus, I have three queries: qryUniv selects only Universities
from tblOrganizations; qrySelectAffiliated selects the University and any
Organization that is affiliated with that University (chosen by cboUniv) or
if cboUniv is Null then it returns all Organizations; qryReverseAffiliated
is identical to qryUniv if cboOrganization is Null and selects only the
University that is affiliated with cboOrganization if it has a value. All
these queries work when run on their own.
What I want is the following:
1. For records on frmContacts where both cboUniv and cboOrganization are
Null (usually these are new records) then the RowSource for cboUniv should
be qryUniv.
2. For records on frmContacts where cboUniv is Null and cboOrganization is
not Null (happens for old records that I made before adding cboUniv and also
for Organizations that are not affiliated with a University, e.g. companies)
then value of cboUniv should be Null or the University from
qryReverseAffiliated.
3. When I select a University on cboUniv, then the list in cboOrganization
will update by qrySelectAffiliated.
Like I said, I've snipped pieces of advice and have come up with the
following, but since I've never worked with VBA before I'm a bit lost as to
why this isn't working:
Private Sub cboUniv_AfterUpdate()
Me.cboOrganization.Requery
End Sub
' This takes care of case 3 above; it seems to work alright.
Private Sub Form_Current()
If IsNull(Me.cboOrganization) Then
Me.cboUniv.RowSource = "qryUniv"
Me.cboUniv.DefaultValue = "Null"
Me.cboUniv.Value = "Null"
Me.cboUniv.Requery
Else
Me.cboUniv.RowSource = "qryReverseAffiliated"
Me.cboUniv.Requery
End If
End Sub
' This produces an error I think...
Private Sub cboUniv_OnGotFocus()
Me.cboUniv.RowSource = "qryUniv"
Me.cboUniv.DefaultValue = Me.cboUniv.Value
Me.cboUniv.Requery
End Sub
' This is so that I can change the value in cboUniv even after cboUniv and
cboOrganization have been set.
Private Sub Organization_NotInList()
Me.cboUniv.RowSource = "qryReverseAffiliated"
Me.cboUniv.Requery
Me.cboOrganization.Requery
End Sub
' This was meant to take care when I choose the wrong cboUniv after
cboOrganization already has a value.
Any help would be *greatly* appreciated. I can provide more info if
necessary, but I'm trying to be as clear as possible here.
TIA,
Stu
can't get this to work nicely:
I have a form frmContacts, that contains an unbound combo box cboUniv and a
bound combo box cboOrganization. The cboUniv is just to make the choices
"pretty," viz., each record in tblContacts has an Organization; the
Organization may be a University or may have an Affiliation with a
University. Thus, I have three queries: qryUniv selects only Universities
from tblOrganizations; qrySelectAffiliated selects the University and any
Organization that is affiliated with that University (chosen by cboUniv) or
if cboUniv is Null then it returns all Organizations; qryReverseAffiliated
is identical to qryUniv if cboOrganization is Null and selects only the
University that is affiliated with cboOrganization if it has a value. All
these queries work when run on their own.
What I want is the following:
1. For records on frmContacts where both cboUniv and cboOrganization are
Null (usually these are new records) then the RowSource for cboUniv should
be qryUniv.
2. For records on frmContacts where cboUniv is Null and cboOrganization is
not Null (happens for old records that I made before adding cboUniv and also
for Organizations that are not affiliated with a University, e.g. companies)
then value of cboUniv should be Null or the University from
qryReverseAffiliated.
3. When I select a University on cboUniv, then the list in cboOrganization
will update by qrySelectAffiliated.
Like I said, I've snipped pieces of advice and have come up with the
following, but since I've never worked with VBA before I'm a bit lost as to
why this isn't working:
Private Sub cboUniv_AfterUpdate()
Me.cboOrganization.Requery
End Sub
' This takes care of case 3 above; it seems to work alright.
Private Sub Form_Current()
If IsNull(Me.cboOrganization) Then
Me.cboUniv.RowSource = "qryUniv"
Me.cboUniv.DefaultValue = "Null"
Me.cboUniv.Value = "Null"
Me.cboUniv.Requery
Else
Me.cboUniv.RowSource = "qryReverseAffiliated"
Me.cboUniv.Requery
End If
End Sub
' This produces an error I think...
Private Sub cboUniv_OnGotFocus()
Me.cboUniv.RowSource = "qryUniv"
Me.cboUniv.DefaultValue = Me.cboUniv.Value
Me.cboUniv.Requery
End Sub
' This is so that I can change the value in cboUniv even after cboUniv and
cboOrganization have been set.
Private Sub Organization_NotInList()
Me.cboUniv.RowSource = "qryReverseAffiliated"
Me.cboUniv.Requery
Me.cboOrganization.Requery
End Sub
' This was meant to take care when I choose the wrong cboUniv after
cboOrganization already has a value.
Any help would be *greatly* appreciated. I can provide more info if
necessary, but I'm trying to be as clear as possible here.
TIA,
Stu