Prev: Update a radio button by combobox selection
Next: Problem using MsgHook to send msg to running app
From: JP... on 12 Jul 2010 13:32 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
From: ralph on 12 Jul 2010 14:24 On Mon, 12 Jul 2010 10:32:57 -0700, JP... <JP(a)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
From: JP... on 12 Jul 2010 16:41 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(a)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 > . >
From: Dee Earley on 13 Jul 2010 03:58 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(a)icode.co.uk) i-Catcher Development Team iCode Systems (Replies direct to my email address will be ignored. Please reply to the group.)
From: Dave O. on 13 Jul 2010 04:45 "JP..." <JP(a)discussions.microsoft.com> wrote in message news:C3A2949E-8B0B-4843-B8E3-BBF824388548(a)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://xkcd.com/327/ Dave O.
|
Pages: 1 Prev: Update a radio button by combobox selection Next: Problem using MsgHook to send msg to running app |