[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

ADO Recordset Find Record

JP

7/12/2010 5:33:00 PM

Hi... I'm using VB6.0 in a Windows XP environment with Microsoft Access 2000
databases.

I have a datagrid on my form attached to and adodc data control. I load the
data control with data from my Access 2000 table. One column is "[Rider
Name]". I want to do a find on the "Patient" (or [Rider Name]).

In a combo box on the form, I select a patient name.

When the focus is lost on the combo box, it goes to the "Lost Focus" event
where:

I define a variable as sCrit for my criteria
I give the criteria the following string:

Chr4(34) & "[Rider Name] = " & chr$(39) & Me.cmbPatient.text & Chr$(39) &
Chr$(34).

That should yield "[Rider Name] = 'CARSON, ROBERT J'"

I say:
me.datGrddata.recordset.find sCrit.

It gives me an error:
"Arguments are of the wrong type, are out of acceptable range, or are in
conflict with one another"...

I use the exact same set of procedures if the operator choosed to select by
the trip ID Number (which is in a string format)...and the record is found
alright...

The primary key on the Access 2000 table is "Date" + Trip Number + Trip
Leg...is it becasue the "[Rider Name]" is not part of the primary key?

Just don't know why I'm getting the error and would appreciate any assistance.

--
Thanks in advance for any assistance you can give me...

JP
4 Answers

ralph

7/12/2010 6:24:00 PM

0

On Mon, 12 Jul 2010 10:32:57 -0700, JP...
<JP@discussions.microsoft.com> wrote:

>Hi... I'm using VB6.0 in a Windows XP environment with Microsoft Access 2000
>databases.
>
>I have a datagrid on my form attached to and adodc data control. I load the
>data control with data from my Access 2000 table. One column is "[Rider
>Name]". I want to do a find on the "Patient" (or [Rider Name]).
>
>In a combo box on the form, I select a patient name.
>
>When the focus is lost on the combo box, it goes to the "Lost Focus" event
>where:
>
>I define a variable as sCrit for my criteria
>I give the criteria the following string:
>
>Chr4(34) & "[Rider Name] = " & chr$(39) & Me.cmbPatient.text & Chr$(39) &
>Chr$(34).
>
>That should yield "[Rider Name] = 'CARSON, ROBERT J'"
>

The only thing that seems worrisome is that "... should yield ..."
part.
Use a Debug.Print statement and make sure.

>I say:
>me.datGrddata.recordset.find sCrit.
>

Also how are you assigning that string to sCrit? The beginning and
terminating Chr$(34)s shouldn't be needed.

-ralph

JP

7/12/2010 8:42:00 PM

0

Thanks Ralph...

The sCrit did yield what I said it did...but, you gave me the answer by
telling me that I did not need the beginning and ending chr(34).

It works...

Thanks for your help
I really appreciate it.

JP


--
Thanks in advance for any assistance you can give me...

JP


"ralph" wrote:

> On Mon, 12 Jul 2010 10:32:57 -0700, JP...
> <JP@discussions.microsoft.com> wrote:
>
> >Hi... I'm using VB6.0 in a Windows XP environment with Microsoft Access 2000
> >databases.
> >
> >I have a datagrid on my form attached to and adodc data control. I load the
> >data control with data from my Access 2000 table. One column is "[Rider
> >Name]". I want to do a find on the "Patient" (or [Rider Name]).
> >
> >In a combo box on the form, I select a patient name.
> >
> >When the focus is lost on the combo box, it goes to the "Lost Focus" event
> >where:
> >
> >I define a variable as sCrit for my criteria
> >I give the criteria the following string:
> >
> >Chr4(34) & "[Rider Name] = " & chr$(39) & Me.cmbPatient.text & Chr$(39) &
> >Chr$(34).
> >
> >That should yield "[Rider Name] = 'CARSON, ROBERT J'"
> >
>
> The only thing that seems worrisome is that "... should yield ..."
> part.
> Use a Debug.Print statement and make sure.
>
> >I say:
> >me.datGrddata.recordset.find sCrit.
> >
>
> Also how are you assigning that string to sCrit? The beginning and
> terminating Chr$(34)s shouldn't be needed.
>
> -ralph
> .
>

Dee Earley

7/13/2010 7:59:00 AM

0

On 12/07/2010 18:32, JP... wrote:
> I define a variable as sCrit for my criteria
> I give the criteria the following string:
>
> Chr4(34)& "[Rider Name] = "& chr$(39)& Me.cmbPatient.text& Chr$(39)&
> Chr$(34).
>
> That should yield "[Rider Name] = 'CARSON, ROBERT J'"

Ralph has already said that the surrounding quotes were the problem, but...

You can include ' and " characters in a VB string without having to
resort to a function call and string concatenation.
This improves readability (normally) and performance if used a lot...

Only the " (and newlines) need to be handled specially in VB strings.
Your code can be written as:
sCrit = """[Rider Name] = '" & Me.cmbPatient.text & "'"""
Which will result in a string containing:
"[Rider Name] = 'blah'".

As said, just remove the "" at each end to get the valid criteria string.

--
Dee Earley (dee.earley@icode.co.uk)
i-Catcher Development Team

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)

John Doe

7/13/2010 8:45:00 AM

0


"JP..." <JP@discussions.microsoft.com> wrote in message
news:C3A2949E-8B0B-4843-B8E3-BBF824388548@microsoft.com...
> Thanks Ralph...
>
> The sCrit did yield what I said it did...but, you gave me the answer by
> telling me that I did not need the beginning and ending chr(34).
>
> It works...
>
> Thanks for your help
> I really appreciate it.
>
> JP
eeek, you are not using any sort of sanitization at all? Your code WILL
crash on a name like O'Brian.
See: http://xkc...

Dave O.