PC Review Forums Newsgroups Microsoft Access Microsoft Access VBA Modules ADO Recordset error

Reply

ADO Recordset error

 
Thread Tools Rate Thread
Old 10-11-2003, 04:41 PM   #1
Robert
Guest
 
Posts: n/a
Default ADO Recordset error


I have gotten off track with the procedure below and
need help finding where I've gone wrong.

Here is what I am trying to do...

I have a form opened which is named Sales. There are
two controls on that form which I am using.

Item and SaleQty

I want to open a recordset of the table tblItem.

There are two controls of tblItem I am going to
use, they are

Item and InStock

Then find the record Item of tblItem which is equal
to Forms!Sales!item.

Once this record is found, then I want to update
the InStock control where

InStock = InStock - SaleQty

This is the code...

Private Sub SaleQty_AfterUpdate()
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
Set rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenKeyset
rst.LockType = adLockOptimistic
rst.Source = "tblItem"
rst.Open Options:=adCmdTable
With rst
.Find [Item]
If .EOF Then
MsgBox "No Item was found!"
Else
.Fields("InStock") = "[InStock] - Forms!Sales!
SaleQty"
.Update
End If
End With
rst.Close
Set rst = Nothing
End Sub
  Reply With Quote
Old 10-11-2003, 07:05 PM   #2
Tim Ferguson
Guest
 
Posts: n/a
Default Re: ADO Recordset error

"Robert" <anonymous@discussions.microsoft.com> wrote in
news:093d01c3a7a1$265bceb0$a501280a@phx.gbl:

> Then find the record Item of tblItem which is equal
> to Forms!Sales!item.
>
> Once this record is found, then I want to update
> the InStock control where
>
> InStock = InStock - SaleQty
>

Well, you don't actually say what is wrong with the code you posted, but I
would do this whole thing in two lines:

' you will need to check the data types and make sure
' that there are quotes in all the right places
strSQL = "UPDATE tblItem " & vbCrLf & _
"SET InStock = InStock - " & Me!SaleQty.Value & vbCrLf & _
"WHERE Item = """ & Forsm!Sales![Item].Value & """;"

' I rarely use the ADO methods, so you'll have to check
' up on the parameters for this, but you should see
' roughly what is meant to happen.
CurrentProject.ActiveConnection.Execute strSQL, _
adoCommandText, adoDoesNotReturnRecords


Hope that helps


Tim F

  Reply With Quote
Old 11-11-2003, 07:49 PM   #3
joe@palladinos.org
Guest
 
Posts: n/a
Default Re: ADO Recordset error

Try setting the source to be rst.Source = "select * tblItem"

-- Joe
  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off