473,322 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Calling an adodb recordset in a text box

I am trying to call a function from a text box on a subform that returns a summed total of a single calculated field. I need to reproduce this function in multiple subforms so it is encapsulated as possible. Here's the code:

Expand|Select|Wrap|Line Numbers
  1. Function Receipts(ByVal CHEMICAL As String) As ADODB.Recordset
  2.     Dim sql As String
  3.     Dim beginningDate As Date
  4.     Dim endingDate As Date
  5.     Dim chemicalID As String
  6.  
  7.     beginningDate = DateAdd("h", 6, [Forms]![frmProduction]![txtBeginningDate])
  8.     endingDate = DateAdd("h", 30, [Forms]![frmProduction]![txtEndingDate])
  9.     chemicalID = CHEMICAL
  10.  
  11. sql = "SELECT (Sum(Abs([tblReceiptScaleData]![WeightIn1]-[tblReceiptScaleData]![WeightOut2]+[tblReceiptScaleData]![WeightIn2]-[tblReceiptScaleData]![WeightOut1]))) AS OffloadQty " _
  12.     & "FROM ItemMasterList INNER JOIN (sPULINH INNER JOIN tblReceiptScaleData ON sPULINH.Pono = tblReceiptScaleData.OrderNumber) ON ItemMasterList.SAGEItemKey = sPULINH.Itemkey " _
  13.     & "WHERE (((ItemMasterList.OperationsDescription) = " & chemicalID & ") AND ((tblReceiptScaleData.TimeOut2) >= " & beginningDate & ") AND ((tblReceiptScaleData.TimeOut2) <= " & endingDate & ")); "
  14. Set Receipts = New ADODB.Recordset
  15. Receipts.Open sql, CurrentProject.Connection, , adLockOptimistic
  16. 'Receipts = rs("OffloadQty")
  17.    Set Receipts = Nothing
The commented out code is from trying to have the function return a variant and using "rs" as the recordset and opening rs and setting Receipts to rs.

As it is I am getting "Syntax error(missing operator) in query expression" and lists out the WHERE clause of my sql.

With it set up using rs as the recordset and returning a variant it gives me "Run-time error '91': Object variable or With block variable not set."


Thanks ahead of time for any help.
Attached Files
File Type: txt vba-Receipts.txt (1.1 KB, 389 views)
Mar 27 '12 #1
5 2204
NeoPa
32,556 Expert Mod 16PB
Digital Oatmeal:
As it is I am getting "Syntax error(missing operator) in query expression" and lists out the WHERE clause of my sql.
In that case I suggest you post the WHERE clause of your SQL for someone to look at.
Mar 27 '12 #2
Rookie mistake. Now I have this:
Expand|Select|Wrap|Line Numbers
  1. SELECT (Sum(Abs([tblReceiptScaleData]![WeightIn1]-[tblReceiptScaleData]![WeightOut2]+[tblReceiptScaleData]![WeightIn2]-[tblReceiptScaleData]![WeightOut1]))) AS OffloadQty
  2. FROM ItemMasterList INNER JOIN (sPULINH INNER JOIN tblReceiptScaleData ON sPULINH.Pono=tblReceiptScaleData.OrderNumber) ON ItemMasterList.SAGEItemKey=sPULINH.Itemkey
  3. WHERE (((ItemMasterList.OperationsDescription) ='BD') And ((tblReceiptScaleData.TimeOut2)>=#3/27/2012 6:00:00 AM#) And ((tblReceiptScaleData.TimeOut2)<=#3/28/2012 6:00:00 AM#));
The sql works...I was missing the "#" signs on the dates.

But now I have "Object variable or With block variable not set" error on the line where the recordset is opened.
Mar 27 '12 #3
SOLVED!!!!!

Here's the code:
Expand|Select|Wrap|Line Numbers
  1. Function Receipts(ByVal CHEMICAL As String) As Variant
  2.     Dim sql As String
  3.     Dim beginningDate As Date
  4.     Dim endingDate As Date
  5.     Dim chemicalID As String
  6.  
  7.     beginningDate = DateAdd("h", 6, [Forms]![frmProduction]![txtBeginningDate])
  8.     endingDate = DateAdd("h", 30, [Forms]![frmProduction]![txtEndingDate])
  9.     chemicalID = CHEMICAL
  10.  
  11. sql = "SELECT (Sum(Abs([tblReceiptScaleData]![WeightIn1]-[tblReceiptScaleData]![WeightOut2]+[tblReceiptScaleData]![WeightIn2]-[tblReceiptScaleData]![WeightOut1]))) AS OffloadQty " _
  12.     & "FROM ItemMasterList INNER JOIN (sPULINH INNER JOIN tblReceiptScaleData ON sPULINH.Pono=tblReceiptScaleData.OrderNumber) ON ItemMasterList.SAGEItemKey=sPULINH.Itemkey " _
  13.     & "WHERE (((ItemMasterList.OperationsDescription) ='" & chemicalID & "') And ((tblReceiptScaleData.TimeOut2)>=#" & beginningDate & "#) And ((tblReceiptScaleData.TimeOut2)<=#" & endingDate & "#)); "
  14. Dim rs As New ADODB.Recordset
  15. rs.Open sql, CurrentProject.Connection, , adLockOptimistic
  16.     If rs.EOF And rs.BOF Then
  17.         rs.Close
  18.     End If
  19. Receipts = rs("OffloadQty")
  20.    Set rs = Nothing
  21.  
  22. End Function
Mar 27 '12 #4
NeoPa
32,556 Expert Mod 16PB
You solved it all by yourself in the end. Good for you.

Sometimes that can happen when you go to the effort of posting a question. Your brain is somehow stimulated to continue working on it, even when you're doing other things. Telling someone about it can have a similar effect. Very helpful, even if that person has no idea what you're on about I find.
Mar 27 '12 #5
Don't give me all the credit. I did have a little help from my friends.

< SNIP >
Mar 31 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Kevin Shea | last post by:
I'm currently running into a problem with ie6 on a windows 2000 machine. I've developed a web application where the client, using JavaScript, opens up an ADODB.Recordset recordset and then reads...
0
by: elcc1958 | last post by:
I need to support a VB6 application that will be receiving disconnected ADODB.Recordset from out DotNet solution. Our dotnet solution deals with System.Data.DataTable. I need to populate a...
0
by: Dot Netizen | last post by:
I am having trouble passing an ADODB.Recordset from a VB6 application to a VB.Net class library using COM Interop. I am running this on XP SP2 with the .Net Framework 1.1 and MDAC 2.8 SP1. I've...
5
by: Simone | last post by:
Hello I hope you guys can help me. I am very new to ADO... I am creating a ADODB connection in a module and trying to access it from a command button in a form. Function fxEIDAssgn(plngEID As...
0
by: CFW | last post by:
I thought this was going to be easy but I'm missing something . . . I need to open an ADODB recordset using the recordset source for a list box on my for. When my form opens, the list box ADODB...
3
by: mark_aok | last post by:
Hi all, All I am trying to do is open a table, edit it, and then close it. But I am having the strangest error. Here is my code Dim i as integer Dim rs as adodb.recordset Set rs = new...
0
by: PCroser | last post by:
I have encountered a problem when querying a table. The query passed data into a recordset which should have resulted in many records but has returned EOF. After debugging the code the only...
1
by: sphinney | last post by:
All, I have a ADODB.Recordset in my Access 2002 project. I've been able to successfully add fields to the record set. According the the MS Access help files, I now must update the recordset to...
6
by: Oko | last post by:
I'm currently developing an MS Access Data Project (.adp) in MS Access 2002. One of the reports within the DB uses data that is Dynamic and cannot be stored on the SQL Server. To resolve this, I...
1
by: shivasusan | last post by:
Hi Friends! Please Help me! How i can solve this error? Please explain me, what is the error and how to solve? Error Type: ADODB.Recordset (0x800A0E7D) The connection cannot be used to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.