PC Review


Reply
Thread Tools Rate Thread

ADO Recordset error

 
 
Robert
Guest
Posts: n/a
 
      10th Nov 2003
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
 
 
 
 
Tim Ferguson
Guest
Posts: n/a
 
      10th Nov 2003
"Robert" <(E-Mail Removed)> wrote in
news:093d01c3a7a1$265bceb0$(E-Mail Removed):

> 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
 
joe@palladinos.org
Guest
Posts: n/a
 
      11th Nov 2003
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dim rs As DAO.Recordset Error Bateman28 Microsoft Access External Data 1 12th Mar 2010 09:42 PM
RE: Recordset error Irene Microsoft Access Getting Started 1 17th May 2008 06:40 AM
Recordset error =?Utf-8?B?aXNiam9ybmVu?= Microsoft Access VBA Modules 1 22nd Mar 2005 03:11 AM
DAO error getting recordset Spammastergrand Microsoft Access Queries 2 19th Dec 2003 03:50 AM
Recordset error Alexis Microsoft Access VBA Modules 1 10th Dec 2003 09:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:43 PM.