Hi Allen - thanks for your response.
The intermediate windows displays:
ppt_no = "12345"
I get a run time error 2001 saying You Canceled the Previous Operation.
When I click Debug, the
varResult = DLookup("house_no", "qry_find_ppt", strWhere)
line of code is highlighted.
I wasn't sure what you meant re the query, but ran my parameter query
that
I
was using in some other tries. It has the house_no (I should have put
this
earlier instead of the PK) and the ppt_no. Both are text fields, BTW.
This
is the resulting SQL:
SELECT tbl_dwelling.house_no, tbl_participants.ppt_no
FROM tbl_dwelling INNER JOIN tbl_participants ON
tbl_dwelling.dwelling_id=tbl_participants.dwelling_id
WHERE (((tbl_participants.ppt_no)=[Enter PPt No]));
I have also tried two other methods (have been working like crazy on
this,
as under a deadline of tomorrow).
One is creating a combo box based on a parameter query. It pulls up
the
ppt_no and the related house_no. If I could just figure out how to
"find"
those into the corresponding fields on the main and sub form, I would
be
fine. Actually, even if it would just find the house number, it would
be
fine, because it would then be easy to scrolll through to find a ppt in
that
house. (House numbers are unique - they aren't the standard house
numbers)
The other is using a search form that open my form. I tried this and
it
worked great, but only opens the subform. I really would like it to
open
the
main form with the subform inside of it. Have no idea if this is
possible.
If so, could just modify my code to openform main and sub instead of
openform
sub only.
I hope I'm making sense - a bit overleaded here and my head is
spinning!
Thanks for any assistance. I really appreciate it.
--
Thanks!
Dee
:
Private Sub txt_find_ppt_no_AfterUpdate()
Dim strWhere As String
Dim varResult As Variant
Dim rs As DAO.Recordset
If Me.Dirty Then Me.Dirty = False
If Not IsNull(Me.txt_find_ppt_no) Then
strWhere = "ppt_no = """ & Me.txt_find_ppt_no & """"
Debug.Print strWhere
varResult = DLookup("dwelling_id", "qry_find_ppt", strWhere)
If IsNull(varResult) Then
MsgBox "Not found"
Else
With Me.RecordsetClone
strWhere = "dwelling_id = """ & varResult & """"
Debug.Print strWhere
.FindFirst strWhere
If .NoMatch Then
MsgBox "Not found. Filtered?"
Else
Me.Bookmark = rs.Bookmark
End If
End With
End If
End If
End Sub
You only need those extra quotes if ppt_no is a Text field (not a
Number
field.) Presumably dwelling_id is a Text field also.
For an explanation of the quotes:
http://allenbrowne.com/casu-17.html
If it doesn't work, press Ctrl+G to open the Immediate Window, and see
what
it printed there. Does the expression look right? To get an example of
what
it should look like, mock up a query, use anything for criteria under
ppt_no
and dwelling_id, then switch it to SQL View (View menu in query
design),
and
look at the WHERE clause.
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Reply to group, rather than allenbrowne at mvps dot org.
I've been busy at work on this and have worked out the error
messages I
was
getting from not declaring rs variable and the text field quotes (I
think!).
Now, when I input a ppt number that exists, though, it just says not
found.
I have removed the Communities main form, so am now working with 1
form
and
1 subform. (Main form is based on tbl_dwelling and contains
address,
etc.,
subform is based on tbl_ppts and contains fields relating to each
individual
in the dwelling.)
Here is my code. I imagine I'm missing something here, of course,
and
apologize for my lack of knowledge. Thanks for your patience.
Private Sub txt_find_ppt_no_AfterUpdate()
Dim strWhere As String
Dim varResult As Variant
Dim rs As Object
If Me.Dirty Then Me.Dirty = False
If Not IsNull(Me.txt_find_ppt_no) Then
strWhere = "ppt_no = "" & Me.txt_find_ppt_no &"""
varResult = DLookup("dwelling_id", "qry_find_ppt", strWhere)
If IsNull(varResult) Then
MsgBox "Not found"
Else
With Me.RecordsetClone
.FindFirst "dwelling_id = " & varResult
If .NoMatch Then
MsgBox "Not found. Filtered?"
Else
Me.Bookmark = rs.Bookmark
End If
End With
End If
End If
End Sub
--
Thanks!
Dee
:
It would not be simple to do this for the subform, since it only
finds
the
records that are loaded there. As you already found, if the wrong
community
is loaded, it won't find the desired record back in the main form
(which
is
what you need in order to load the right record into the subform.)
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Reply to group, rather than allenbrowne at mvps dot org.
Just as an aside, Allen. Is there any way that I can modify your
FindAsYouType code so that I can use this in my subforms? I love
the
flexibility it offers in terms of searching any of the form
fields.
Thanks again!
--
Thanks!
Dee
:
The form is bound to a table, I presume.
You may need to add a reference to the DAO library:
http://allenbrowne.com/ser-38.html
That reference is present by default in all versions of Access
except
2000
and 2002.
Ultimiately you will need to modify (and extend) the code to
handle
your
field names etc. I've assumed these are Number fields; if they
are
text
you
need extra quotes:
http://allenbrowne.com/casu-17.html
I tried the code, placing the text box in the header of the
main
form.
I get a Variable not defined error message which stops at:
Me.Bookmark = rs.Bookmark
Highlighting rs.
I don't want to start fooling around with your code. Any
suggestions?
Thank you.
--
Thanks!
Dee
:
Dee, I take it you have 3 tables like this:
- Community table, with CommunityID primary key;
- House table, with HouseID primary key, and CommunityID
foreign
key;
- Person table, with PersonID primary key, and HouseID
foreign
key.
You interfaced this with:
- MainForm bound to Community table;
- Subform1 bound to House table;
- Subform2 (a sub-subform) bound to Person table.
Now you want to add a text box to MainForm where the user can
enter
a
PersonID number, and it will load the correct community into
the
main
form,
the correct House into the subform, and choose the correct
person
in
the
sub-subform. Is that the idea?
This example shows how you might respond to unbound text box
named
txtFIndPersonID. You will need a query that uses all 3
tables,
and
shows
the
3 key fields. The example below assumes it is named Query1.
Private Sub txtFindPersonID_AfterUpdate
Dim strWhere As String
Dim varResult As Variant
If Me.Dirty Then Me.Dirty = False
If Not IsNull(Me.txtFindPersonID) Then
strWhere = "PersonID = " & Me.txtFindPersonID
varResult = DLookup("CommunityID", "Query1",
strWhere)
If IsNull(varResult) then
MsgBox "Not found"
Else
With Me.RecordsetClone
.FindFirst "CommunityID = " & varResult
If .NoMatch Then
MsgBox "Not found. Filtered?"
Else
Me.Bookmark = rs.Bookmark
'Repeat the same logic to find the house
in
the
subform.
End If
End With
End If