Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 17th, 2005, 09:37 AM
richapita richapita is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 5 richapita User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 18 sec
Reputation Power: 0
Help with ADO...

My first real attempt at using an ADO connection. Have always used bound forms in the past.
Please review my code and offer help! Getting an error...Object variable or With block variable not set.

Private Sub btnPreviewChecks_Click()
Dim rstTemp As ADODB.Recordset
Dim CurConn As ADODB.Connection
Dim strSQL As String
Dim strCheckNo As Long
Dim strEnglish As String
Dim curAmount As Currency

Set CurrConn = CurrentProject.Connection

strCheckNo = Me.txtStartingCheckNumber
strSQL = "SELECT * from tblChecksPendingPrint"

rstTemp.Open "tblcheckspendingpring", CurrConn, adOpenDynamic, adLockOptimistic, adCmdTable
rstTemp.Source = strSQL



rstTemp.MoveFirst
Do Until rstTemp.EOF
chkNumber = strCheckNo
chkPrintDate = Date

curAmount = chkAmount.Value
strEnglish = DollarsAndCents(curAmount)
chkAmountEnglish = strEnglish

strCheckNo = strCheckNo + 1

rstTemp.MoveNext
Loop

rstTemp.Close

Set rstTemp = Nothing
End Sub


Thanks

Reply With Quote
  #2  
Old March 17th, 2005, 02:06 PM
pmcnamee pmcnamee is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 13 pmcnamee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 12 m 52 sec
Reputation Power: 0
Not that it matters too much, but are you using Visual Basic or ASP?

Reply With Quote
  #3  
Old March 17th, 2005, 02:25 PM
richapita richapita is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 5 richapita User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 18 sec
Reputation Power: 0
Access 2003

Quote:
Originally Posted by pmcnamee
Not that it matters too much, but are you using Visual Basic or ASP?

Reply With Quote
  #4  
Old March 17th, 2005, 02:25 PM
richapita richapita is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 5 richapita User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 18 sec
Reputation Power: 0
Access 2003

Reply With Quote
  #5  
Old March 17th, 2005, 02:53 PM
pmcnamee pmcnamee is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 13 pmcnamee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 12 m 52 sec
Reputation Power: 0
Try this:
Code:
 rstTemp.Open strSQL, CurrConn, adOpenDynamic, adLockOptimistic, adCmdTable
 


You're trying to set the recordset's source after already trying to open it with a different source.

Quote:
For the other arguments that correspond directly to properties of a Recordset object (Source, CursorType, and LockType), the relationship of the arguments to the properties is as follows:

  • The property is read/write before the Recordset object is opened.
  • The property settings are used unless you pass the corresponding arguments when executing the Open method. If you pass an argument, it overrides the corresponding property setting, and the property setting is updated with the argument value.
  • After you open the Recordset object, these properties become read-only.

Reply With Quote
  #6  
Old March 17th, 2005, 03:47 PM
richapita richapita is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 5 richapita User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 18 sec
Reputation Power: 0
Attempted code change, get same error pointing at:

rstTemp.Open strSQL, CurrConn, adOpenDynamic, adLockOptimistic, adCmdTable

object variable or with block not set

I'm stumped appreciate any help...been doing alot of reading...hasn't helped any.

HELP!!!

Reply With Quote
  #7  
Old March 17th, 2005, 10:32 PM
pmcnamee pmcnamee is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 13 pmcnamee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 12 m 52 sec
Reputation Power: 0
I'm looking into it but I believe you need to open the connection before using it for the recordset.

Use:
Code:
 CurrConn.Open
 
 rstTemp.Open strSQL, CurrConn, adOpenDynamic, adLockOptimistic, adCmdTable

Reply With Quote
  #8  
Old March 18th, 2005, 09:07 AM
richapita richapita is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 5 richapita User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 18 sec
Reputation Power: 0
Operation is not allowed when the object is open


I appreciate your help...Still reading on my side...can't figure it out!

Reply With Quote
  #9  
Old March 18th, 2005, 10:22 AM
pmcnamee pmcnamee is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 13 pmcnamee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 12 m 52 sec
Reputation Power: 0
I'm not sure if this makes a huge difference but I forgot to change one parameter for the .Open method earlier.

rstTemp.Open strSQL, CurrConn, adOpenDynamic, adLockOptimistic, adCmdTable

The last option should be adCmdText instead of adCmdTable. With adCmdTable, it thinks that strSQL is a table name, not a SQL statement.

I'm sorry about the un-helpful posts earlier. The majority of my ado experience has been with vb6 and ASP.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > Help with ADO...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT