Re: Error : Item not found in this collection
- From: Jim C. <JimC@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 24 Jun 2005 07:49:12 -0700
You probably missed the change in the definition of qd to be QueyDef not
QueryDefs. I should have pointed that out since it's easily missed.
Jim C.
"spowell15@xxxxxxxxxxx" wrote:
> Thanks for such a quick response Jim.
>
> I have changed my code to match what you have provided, I now get an
> error on the If statement:
>
> If qd.Name = "MemoUpdate" Then
>
> I get Compile error: Methode or data member not found, the qd.Name is
> highlighted.
>
> any idea why this is happening,
>
> Shirley
>
> Jim C. wrote:
> > "spowell15@xxxxxxxxxxx" wrote:
> >
> > > Hi All,
> > >
> > > I am trying to run an Update query in SQL to a memo field. I get the
> > > error message 'Item not found in this collection'. I have posted my
> > > code below. Anyone got any ideas what I am doing wrong? Any help
> > > would be greatly appreciated.
> > >
> > > Dim db As DAO.Database
> > > Dim qd As DAO.QueryDefs
> > > Dim strSQL As String
> > >
> > > Set db = CurrentDb
> > > Set qd = db.QueryDefs("strSQL")
> > >
> > > qd!Parameters("ActDate") = "[Forms]![Action_Diary_frm]![Action Date]"
> > > qd!Parameters("ActTaken") = "[Forms]![Action_Diary_frm]![Action
> > > Taken]"
> > > qd!Parameters("Coms") = "[Forms]![Action_Diary_frm]![Comments]"
> > > db.QueryDefs("strSQL").Execute
> > > strSQL = "UPDATE [Action_Diary] SET [Action_Diary].[Action Date] =
> > > [Act], [Action_Diary].[Action Taken]=
> > > [ActTaken],[Action_Diary].[Comments] = [Coms] WHERE
> > > [Action_Diary].[Action_ID] = [Forms]![Action_Diary_frm]![Action_ID] "
> > >
> > > Thanks,
> > >
> > > Shirley
> > >
> > >
> >
> > While you are on the right track, there are a number of syntax problems with
> > your code, beyoind the error you ar currently getting. I removed the
> > parameters as they are not necessary since I am recreating the query each
> > time through.
> >
> >
> > Dim db As Database
> > Dim qd As QueryDef
> > Dim strSQL As String
> >
> > Set db = CurrentDb
> >
> > 'If the query used for this routine already exists, it is deleted so that it
> > can be
> > ' recreated with the values from the form
> > For Each qd In db.QueryDefs
> > If qd.Name = "MemoUpdate" Then
> > db.QueryDefs.Delete qd.Name
> > Exit For
> > End If
> > Next qd
> >
> > strSQL = "UPDATE [Action_Diary] SET [Action_Diary].[Action Date] = " &
> > [Forms]![Action_Diary_frm]![Action Date] & ", [Action_Diary].[Action Taken]=
> > " &
> > [Forms]![Action_Diary_frm]![Action Taken] & ",[Action_Diary].[Comments] = "
> > & [Forms]![Action_Diary_frm]![Comments] & " WHERE
> > [Action_Diary].[Action_ID] = " & [Forms]![Action_Diary_frm]![Action_ID] & ";"
> >
> > Set qd = dbs.CreateQueryDef("MemoUpdate", strSQL)
> > qd.Execute
> >
> >
> > An alternative to this is to save the query using parameters to receive the
> > form data, and then from this routine, do not delete the querydef, only
> > populate the parameters, and then execute the query. This assumes that no
> > one would have modified the querydef in some way that you don't anticipate.
> >
> > Jim C.
>
>
.
- Follow-Ups:
- Re: Error : Item not found in this collection
- From: spowell15@xxxxxxxxxxx
- Re: Error : Item not found in this collection
- References:
- Error : Item not found in this collection
- From: spowell15@xxxxxxxxxxx
- RE: Error : Item not found in this collection
- From: Jim C.
- Re: Error : Item not found in this collection
- From: spowell15@xxxxxxxxxxx
- Error : Item not found in this collection
- Prev by Date: Re: Automatically accepting YES in update query
- Next by Date: Re: Error : Item not found in this collection
- Previous by thread: Re: Error : Item not found in this collection
- Next by thread: Re: Error : Item not found in this collection
- Index(es):
Relevant Pages
|