PC Review


Reply
Thread Tools Rate Thread

ADODB Question

 
 
OD
Guest
Posts: n/a
 
      10th Jun 2009
Hi
I hope I got all the necessary procedures. I am getting the following error
when opening the database. Everything looks good until almost the end and for
some reason it looks like the db is opening up in add mode (the table is
coming back as empty and there is information in it),

An error has occurred in the application
Error Number 91
Error Description Object variable or With block variable not set
Module Source frmPurchaseEntryScreen3
procedure Source LoadRecords

Here are the processes leading to this

Private Sub Form_Load()
On Error GoTo HandleError


Set objPurchase = New clsPurchase
Set rsPurchase = New ADODB.Recordset

blnAllRecords = True
Call LoadRecords
Exit Sub

HandleError:
GeneralErrorHandler Err.Number, Err.Description, PURCHASE_FORM,
"Form_Load"
Exit Sub
End Sub

Sub LoadRecords()
On Error GoTo HandleError

intCurPurchRecord = 0
blnAddMode = False
Set rsPurchase = objPurchase.RetrievePurchase(blnAllRecords)
If rsPurchase.BOF And rsPurchase.EOF Then
MsgBox "There are no records in the database"
Exit Sub
Else
objPurchase.PopulatePropertiesFromRecordset rsPurchase
Call MoveToFirstRecord(intCurPurchRecord, rsPurchase, objPurchase,
blnAddMode)
Call PopulatePurchaseControls
End If

Exit Sub

HandleError:
GeneralErrorHandler Err.Number, Err.Description, PURCHASE_FORM,
"LoadRecords"
Exit Sub
End Sub

Function RetrievePurchase(blnAllRecords As Boolean) As ADODB.Recordset
On Error GoTo HandleError

Dim strSQLStatement As String
Dim rsPurch As New ADODB.Recordset

strSQLStatement = BuildSQLSelectPurchase(blnAllRecords)

Set rsPurch = ProcessRecordset(strSQLStatement)

Exit Function

HandleError:
GeneralErrorHandler Err.Number, Err.Description, CLS_PURCHASE,
"RetrievePurchase"
Exit Function
End Function

Function BuildSQLSelectPurchase(blnAllRecords As Boolean) As String
On Error GoTo HandleError

Dim strSQLretrieve As String
If intPurchLookup = 0 Then
strSQLretrieve = "SELECT * FROM tblPurchReq ORDER BY PRNum"
End If

BuildSQLSelectPurchase = strSQLretrieve
Exit Function


HandleError:
GeneralErrorHandler Err.Number, Err.Description, DB_LOGIC,
"BuildSQLRetrievePurchase"
Exit Function

End Function


Function ProcessRecordset(strSQLStatement As String) As ADODB.Recordset
On Error GoTo HandleError

Call OpenDBConnection
Dim rsPurch As New ADODB.Recordset

With rsPurch
.CursorType = adOpenKeyset
.CursorLocation = adUseClient
.LockType = adLockBatchOptimistic
.Open strSQLStatement, cnConn
.ActiveConnection = Nothing
End With

Call CloseDBConnection
Set ProcessRecordset = rsPurch

Exit Function


HandleError:
GeneralErrorHandler Err.Number, Err.Description, DB_LOGIC,
"ProcessRecordset"
Exit Function
End Function

 
Reply With Quote
 
 
 
 
vanderghast
Guest
Posts: n/a
 
      10th Jun 2009
Your object objPurchase is probably not initialized properly. It is not
Nothing, since you use


Set objPurchase = New clsPurchase


but unless you define an initilizer in your class Purchase,

Private Sub Class_Initialize()
...
End Sub


all its local variables (attributes) will be set to default, 0 for
numerical, empty string for strings variables, and its RetrievePurchase
method won't be able to do much, at the line:

Set rsPurchase = objPurchase.RetrievePurchase(blnAllRecords)


That is a very weak point of VBA, to not be able to Initialize the object
with arguments, so you would probably need some extra method to do it:

Set objPurchase = New clsPurchase
objPurchase.InitializeConnection( .... parameters here ... ) '
NEW LINE OF CODE


Note that proceeding this way is very prone to lead to memory leak, with
VBA, though, if your initialization create/activate other 'objects' .



Vanderghast, Access MVP



"OD" <(E-Mail Removed)> wrote in message
news:108E9497-053A-4F9E-AA06-(E-Mail Removed)...
> Hi
> I hope I got all the necessary procedures. I am getting the following
> error
> when opening the database. Everything looks good until almost the end and
> for
> some reason it looks like the db is opening up in add mode (the table is
> coming back as empty and there is information in it),
>
> An error has occurred in the application
> Error Number 91
> Error Description Object variable or With block variable not set
> Module Source frmPurchaseEntryScreen3
> procedure Source LoadRecords
>
> Here are the processes leading to this
>
> Private Sub Form_Load()
> On Error GoTo HandleError
>
>
> Set objPurchase = New clsPurchase
> Set rsPurchase = New ADODB.Recordset
>
> blnAllRecords = True
> Call LoadRecords
> Exit Sub
>
> HandleError:
> GeneralErrorHandler Err.Number, Err.Description, PURCHASE_FORM,
> "Form_Load"
> Exit Sub
> End Sub
>
> Sub LoadRecords()
> On Error GoTo HandleError
>
> intCurPurchRecord = 0
> blnAddMode = False
> Set rsPurchase = objPurchase.RetrievePurchase(blnAllRecords)
> If rsPurchase.BOF And rsPurchase.EOF Then
> MsgBox "There are no records in the database"
> Exit Sub
> Else
> objPurchase.PopulatePropertiesFromRecordset rsPurchase
> Call MoveToFirstRecord(intCurPurchRecord, rsPurchase, objPurchase,
> blnAddMode)
> Call PopulatePurchaseControls
> End If
>
> Exit Sub
>
> HandleError:
> GeneralErrorHandler Err.Number, Err.Description, PURCHASE_FORM,
> "LoadRecords"
> Exit Sub
> End Sub
>
> Function RetrievePurchase(blnAllRecords As Boolean) As ADODB.Recordset
> On Error GoTo HandleError
>
> Dim strSQLStatement As String
> Dim rsPurch As New ADODB.Recordset
>
> strSQLStatement = BuildSQLSelectPurchase(blnAllRecords)
>
> Set rsPurch = ProcessRecordset(strSQLStatement)
>
> Exit Function
>
> HandleError:
> GeneralErrorHandler Err.Number, Err.Description, CLS_PURCHASE,
> "RetrievePurchase"
> Exit Function
> End Function
>
> Function BuildSQLSelectPurchase(blnAllRecords As Boolean) As String
> On Error GoTo HandleError
>
> Dim strSQLretrieve As String
> If intPurchLookup = 0 Then
> strSQLretrieve = "SELECT * FROM tblPurchReq ORDER BY PRNum"
> End If
>
> BuildSQLSelectPurchase = strSQLretrieve
> Exit Function
>
>
> HandleError:
> GeneralErrorHandler Err.Number, Err.Description, DB_LOGIC,
> "BuildSQLRetrievePurchase"
> Exit Function
>
> End Function
>
>
> Function ProcessRecordset(strSQLStatement As String) As ADODB.Recordset
> On Error GoTo HandleError
>
> Call OpenDBConnection
> Dim rsPurch As New ADODB.Recordset
>
> With rsPurch
> .CursorType = adOpenKeyset
> .CursorLocation = adUseClient
> .LockType = adLockBatchOptimistic
> .Open strSQLStatement, cnConn
> .ActiveConnection = Nothing
> End With
>
> Call CloseDBConnection
> Set ProcessRecordset = rsPurch
>
> Exit Function
>
>
> HandleError:
> GeneralErrorHandler Err.Number, Err.Description, DB_LOGIC,
> "ProcessRecordset"
> Exit Function
> End Function
>


 
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
ADODB Question =?Utf-8?B?bHV2Z3JlZW4=?= Microsoft Excel Programming 8 15th Nov 2004 11:46 AM
URGENT HELP ADODB VbScript vs ADODB.ConnectionClass() C# =?Utf-8?B?U2lsdmlhIEJydW5ldCBKb25lcw==?= Microsoft Dot NET Framework 9 13th Oct 2004 04:31 PM
Re: URGENT HELP ADODB VbScript vs ADODB.ConnectionClass() C# Lucas Tam Microsoft ADO .NET 0 29th Jul 2004 04:34 AM
a simple question on ADODB joyo Microsoft Access Form Coding 1 16th Apr 2004 05:38 PM
ADODB Fields Question Ivan Sammut Microsoft C# .NET 2 27th Dec 2003 11:43 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:06 AM.