HELP - What Am I Doing Wrong 
Author Message
 HELP - What Am I Doing Wrong

I use Access 2000 db with 2 tables - 'Fname and Lname"
    I need to search a record by first name and last name using ADO but also
need to have an error message pop up when the names are not found. I use the
code:

Private Sub cmdSearch_Click()
'
    Dim strNameA as String
    Dim strNameB as String
'
strNameA = InputBox("Enter first name:", "Find Participant")
If strNameA = "" Then
    Exit Sub
End If

strNameB = InputBox("Enter last name:", "Find Participant")
If strNameB = "" Then
    Exit Sub
End If

With Me.Data1.Recordset
    .Find "Fname=" & strNameA & "Lname=" & strNameB
End With
'
End Sub

What Am I Doing Wrong?

Thanks
                Jay



Wed, 08 Oct 2003 02:18:17 GMT  
 HELP - What Am I Doing Wrong
When you say "2 tables - 'Fname and Lname: I assume you mean columns/fields
and not tables.

Actually you have a number of problems.

Firstly, the problem is quotes and spaces!

Correcting for that you would think this would work...

    With Me.Data1.Recordset
        .Find "Fname='" & strNameA & "' AND Lname='" & strNameB & "'"
    End With

...however, the Find method only allows ONE column to be specified, so using
Find you can only use Fname OR LName.

RichardF

--


Quote:
> I use Access 2000 db with 2 tables - 'Fname and Lname"
>     I need to search a record by first name and last name using ADO but
also
> need to have an error message pop up when the names are not found. I use
the
> code:

> Private Sub cmdSearch_Click()
> '
>     Dim strNameA as String
>     Dim strNameB as String
> '
> strNameA = InputBox("Enter first name:", "Find Participant")
> If strNameA = "" Then
>     Exit Sub
> End If

> strNameB = InputBox("Enter last name:", "Find Participant")
> If strNameB = "" Then
>     Exit Sub
> End If

> With Me.Data1.Recordset
>     .Find "Fname=" & strNameA & "Lname=" & strNameB
> End With
> '
> End Sub

> What Am I Doing Wrong?

> Thanks
>                 Jay



Wed, 08 Oct 2003 02:45:03 GMT  
 HELP - What Am I Doing Wrong
Try using Filter rather than Find:
Me.Data1.Recordset.Filter="Fname='" & strNameA & "' AND Lname='" & strNameB
& "'"

This will reduce the recordset to just those records matching the filter.
To test if NO records match, use EOF AND BOF:
IF Me.Data1.Recordset.EOF AND Me.Data1.Recordset.BOF Then
    MSgbox "No Records Match"
Else
    Msgbox Me.Data1.Recordset.RecordCount & " Records Found"
End If

Remember to take the filter off again when you are finished:
Me.Data1.Recordset.Filter=""


Quote:
> When you say "2 tables - 'Fname and Lname: I assume you mean
columns/fields
> and not tables.

> Actually you have a number of problems.

> Firstly, the problem is quotes and spaces!

> Correcting for that you would think this would work...

>     With Me.Data1.Recordset
>         .Find "Fname='" & strNameA & "' AND Lname='" & strNameB & "'"
>     End With

> ...however, the Find method only allows ONE column to be specified, so
using
> Find you can only use Fname OR LName.

> RichardF

> --



> > I use Access 2000 db with 2 tables - 'Fname and Lname"
> >     I need to search a record by first name and last name using ADO but
> also
> > need to have an error message pop up when the names are not found. I use
> the
> > code:

> > Private Sub cmdSearch_Click()
> > '
> >     Dim strNameA as String
> >     Dim strNameB as String
> > '
> > strNameA = InputBox("Enter first name:", "Find Participant")
> > If strNameA = "" Then
> >     Exit Sub
> > End If

> > strNameB = InputBox("Enter last name:", "Find Participant")
> > If strNameB = "" Then
> >     Exit Sub
> > End If

> > With Me.Data1.Recordset
> >     .Find "Fname=" & strNameA & "Lname=" & strNameB
> > End With
> > '
> > End Sub

> > What Am I Doing Wrong?

> > Thanks
> >                 Jay



Wed, 08 Oct 2003 04:07:06 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. HELP: what am i doing wrong??

2. HELP: what am i doing wrong??

3. Help: What am I doing wrong?

4. HELP: what am i doing wrong??

5. Help with syntax. What am I doing wrong

6. Help on GPF...what am I doing wrong???

7. What am i doing wrong here????? HELP

8. Recordset: What am I doing wrong?

9. What am I doing wrong??

10. What am I doing wrong?

11. What am I doing wrong?

12. What am I doing wrong?

 

 
Powered by phpBB® Forum Software