Hi Allen, Me again.
I'm getting used to the dlookup and it's working well for me.
My question is can I lookup TWO attributes with it?
I want to lookup the Product Make and the RS number so that when I have
the
Make it also gives me the RS Number which I can then use as the trigger
for
the form Whereis attribute.
The reason for this is the old Subform dilemma. I have the Make
displayed
in
the subform but want the find to bring up the Main forms' record.
Here's what I've done so far...
Private Sub txtFindMake_AfterUpdate()
'Find a Make in the RS table and Display from the RSNO
Dim strWhereMake As String
Dim strFoundMake As String
Dim FoundRSNo As Integer
If Not IsNull(Me.txtFindMake) Then
strWhereMake = "[Make] = '" & Me.txtFindMake & "'"
strFoundMake = DLookup("Make", "RS_Results", strWhereMake)
MsgBox strFoundMake, vbOKCancel, "Here is the Make" ' This is just
to
test the find
'Close this form
DoCmd.Close
'Make the RELEASE Button visible
Forms!sorma_records_edit.cmdReleaseFilter.Visible = True
'Open the Edit form at the appropriate record
DoCmd.OpenForm "Sorma_Records_Edit", , , strWhereMake
End If
End Sub
the DoCmd does not work as the Field Make is on the subform
What I want is the RS Number for that Make (there may be many
occurrences
of
this but I'll deal with that later) so that I can display the Main form
from
the RS Number.
Hope that's clear.
I know it's getting complicated and I really need to go back to your
http://allenbrowne.com/ser-28.html
page and work on this but I just thought that the dlookup for multiple
attributes might be easier for now.
--
Cheers
Chas
***************
* Spectrum is Green *
***************
:
DLookup() would be the simplest way to see if the number is in the
table.
It
will return Null if the entry is not found.
Use the BeforeUpdate event of you want to keep the user in the box
until
they enter something valid.
Private Sub txtSearchSorma_BeforeUpdate(Cancel As Integer)
Dim strWhere As String
If Not IsNull(Me.txtSearchSorma) Then
strWhere = "[SORMA] = " & Me.txtSearchSorma
If IsNull(DLookup("SORMA", "Table1", strWhere)) Then
Cancel = True
MsgBox "No such entry." & vbCrLf & _
"Correct the entry, or press <Esc> to undo."
End If
End With
End Sub
More info on DLookup():
Getting a value from a table: DLookup()
at:
http://allenbrowne.com/casu-07.html
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
Dear Allen,
Thanks again for the speedy reply.
Actually I'm not looking to see if there are ANY records in the
table,
I
know there is, what I want to do is validate that the record with
the
number
entered by the user exists.
The table has several dummy entries at present.
The SORMA field is not the autonumber field it is a numeric field.
The data at present looks like 1231, 1232, 1234, 1235 etc.
If the user enters any number which is NOT in the field SORMA (e.g.,
2244)
I
want to tell him and put the focus back to the text box.
Currently when I enter a number thats in the Table the record is
shown
with
that value in the SORMA field box. If I enter a false value, a blank
record
is shown with the value 0 in the SORMA field Box.
--
:
I think you are trying to determine whether there are any records
in
the
form Sorma_Results when you open it?
If so:
If Forms!Sorma_Results.RecordsetClone.RecordCount > 0 Then
MsgBox "Yep: found some."
End If
Thanks for the link Allen,
I had looked at this before when trawling through the groups.
Unfortunately
I cannot seem to get it to work and for now am not too bothered
as
I'm
still
learning and have ordered a couple of books on Access to learn
more.
(Access
2000 Bible & MS Access Step by step). Could you recommend a
better
one?
I have tried one of your earlier tips on searching and made that
work.
I
have Created a form which opens on clicking a button on the main
form.
Here
the user can enter a number for one of either two searches, I'll
incorporate
more when I can.
Here is the code from the After Update event of one of the Text
boxes
which
searches for a record field then opens the data form at that
record.
Private Sub txtSearchSorma_AfterUpdate()
'Find a SORMA Number
Dim strWhere As String
If Not IsNull(Me.txtSearchSorma) Then
strWhere = "[SORMA] = " & Me.txtSearchSorma
DoCmd.OpenForm "Sorma_Results", , , strWhere
End If
End Sub
The Table is SORMA_Results and the Field is "SORMA" a numeric
field.
This works well if the record exists but if not then the record
selected
is
blank with the value for SORMA showing 0 (zero).
What I want to do is put in an IF THEN statement before the DoCmd
line
to
check if the value of SORMA within the table SORMA_Results is
valid,
i.e.,
it
has a value.
I have tried various forms of IF [SORMA_Results]![SORMA] = 0
Then...
and
so
on but keep getting a debug that says the Field | cannot be
found.
How do I correctly address a Table & Field within an IF THEN
Statement?
Is there a Reference File anywhere which lists this kind of
information
as
I
cannot seem to find it in Access help.
Cheers
Chas
--
Spectrum is Green
:
Hi Chas
See:
Filter a Form on a Field in a Subform
at:
http://allenbrowne.com/ser-28.html
The article describes how to respond to the user input to that
it
effectively filters the main form to show only records that have
a
match
in
the subform (by assigning an INNER JOIN statement to its
RecordSource),
and
how to combine that technique with filters on the main form's
fields
at
the
same time.
message
Hi All,
I have searched the groups for an answer but can't find it so
far...
I have a form 'Customers' and it has an embedded? Sub-Form
'Product'.
I have a Find button - via the cmd button wizard which brings
up
the
Find
&
Replace Dialog. Having selected the field in either the
Customer
or
Product
forms I can indeed 'Find' a record. However, whilst the
Customer
Find
is
OK,
the Product Find will only let me find records relating to the
selected
customer. What I need is a Find that will allow me to search
for
records
in
the Product Table and bring up the Customer Record and the
corresponding
Product Record in the sub-form.
The Forms Record Sources are the relevent Tables not a query.
Do I need to build some form of SEARCH Dialog of my own to
find
the
relevent
records? is the standard Find button too simple?
Here is the code for the Find Button:-
Private Sub cmdFindCUSTRec_Click()
'Search for Customer Records
On Error GoTo Err_cmdFindCUSTRec_Click
Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70
Exit_cmdFindCUSTRec_Click:
Exit Sub
Err_cmdFindCUSTRec_Click:
MsgBox Err.Description
Resume Exit_cmdFindCUSTRec_Click
End Sub
I don't want someone to do this for me just point me to
somewhere
I
can
learn how to do it. I am familiar with VBA it's just how you
pull
this
info
together I can't work out. New to SQL etc.