Error msg: Object variable or With block variable not set 
Author Message
 Error msg: Object variable or With block variable not set

Error msg: Object variable or With block variable not set

Does anyone know what this error is coming from? The help file is not too
helpful. The error occurs in the following Sub routine between the two
asterisked lines. The query does exist and works. I am using recordsets
through out my module, the only difference is that the is the first time I
used a query and used a query with such a long name. What I did get from the
help file is that it is permitted to use queries for a RecordSet.

TIA

Scott

'------------------------------------------------------------------
' Exportdata()
' Create the text output export file
'------------------------------------------------------------------
Public Sub Exportdata()
On Error GoTo exportdata_Err
Dim pvNewFileName As String
Dim db As Database
Dim pvrst As DAO.Recordset

DoCmd.SetWarnings False
;********************************************************
Set pvrst = db.OpenRecordset("tblMain Without Matching tblRetail_Cost")
;********************************************************
If pvrst.EOF Then
     'spacer
Else
     sendemail 'some external sub routine
     DoCmd.TransferSpreadsheet acExport, 8, "tblMain Without Matching
tblRetail_Cost", "Missing Retail_Cost Adjustments", True, ""
     CloseApp 'some external sub routine
End If

pvNewFileName = OutputFilename 'some external sub routine

'DoCmd.TransferText acExportDelim, "ExportNonPromo", "qryExportOutput",
gvMaindir & "\output\" & pvNewFileName & ".txt", True, ""
DoCmd.TransferText acExportDelim, "ExportNonPromo", "Output", gvMaindir &
"\output\" & pvNewFileName & ".txt", True, ""

DoCmd.SetWarnings True

exportdata_Exit:
     Exit Sub

exportdata_Err:
     sendemail 'some external sub routine
     CloseApp 'some external sub routine

End Sub 'Exportdata()



Mon, 22 Nov 2004 05:27:13 GMT  
 Error msg: Object variable or With block variable not set
You have forgotten to "Set" the db variable to "CurrentDb", hence the error

While we're at it, you have also forgotten to close and set your recordset
variable to nothing

pvrst.Close
Set pvrst = Nothing

Steve


Quote:
> Error msg: Object variable or With block variable not set

> Does anyone know what this error is coming from? The help file is not too
> helpful. The error occurs in the following Sub routine between the two
> asterisked lines. The query does exist and works. I am using recordsets
> through out my module, the only difference is that the is the first time I
> used a query and used a query with such a long name. What I did get from
the
> help file is that it is permitted to use queries for a RecordSet.

> TIA

> Scott

> '------------------------------------------------------------------
> ' Exportdata()
> ' Create the text output export file
> '------------------------------------------------------------------
> Public Sub Exportdata()
> On Error GoTo exportdata_Err
> Dim pvNewFileName As String
> Dim db As Database
> Dim pvrst As DAO.Recordset

> DoCmd.SetWarnings False
> ;********************************************************
> Set pvrst = db.OpenRecordset("tblMain Without Matching tblRetail_Cost")
> ;********************************************************
> If pvrst.EOF Then
>      'spacer
> Else
>      sendemail 'some external sub routine
>      DoCmd.TransferSpreadsheet acExport, 8, "tblMain Without Matching
> tblRetail_Cost", "Missing Retail_Cost Adjustments", True, ""
>      CloseApp 'some external sub routine
> End If

> pvNewFileName = OutputFilename 'some external sub routine

> 'DoCmd.TransferText acExportDelim, "ExportNonPromo", "qryExportOutput",
> gvMaindir & "\output\" & pvNewFileName & ".txt", True, ""
> DoCmd.TransferText acExportDelim, "ExportNonPromo", "Output", gvMaindir &
> "\output\" & pvNewFileName & ".txt", True, ""

> DoCmd.SetWarnings True

> exportdata_Exit:
>      Exit Sub

> exportdata_Err:
>      sendemail 'some external sub routine
>      CloseApp 'some external sub routine

> End Sub 'Exportdata()



Mon, 22 Nov 2004 05:38:24 GMT  
 Error msg: Object variable or With block variable not set
Thanks Steve, I'll give it a try tomorrow. It's funny that this error never
came up before, but I looked at another routine in another database and I
use it there.

Quote:
> You have forgotten to "Set" the db variable to "CurrentDb", hence the

error

Is this needed for "good tight programming practice"? I guess I never really
closed a recordset because all of my routines are automated and quit Access
as soon as a process is done. It'll probably bite me later if I don't start
using these.

Quote:
> While we're at it, you have also forgotten to close and set your recordset
> variable to nothing

> pvrst.Close
> Set pvrst = Nothing

> Steve



Mon, 22 Nov 2004 12:32:45 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. dhSortedDictionary empty key error msg = Object variable or With block variable not set

2. Object variable or With block variable not set (Error 91)

3. error 91 Object Variable o on with block variable is not set

4. Runtime error 91/Object variable or With block variable not set problems

5. Object variable or With block variable not set error in Class

6. runtime error: 91 Object variable or with block variable not set

7. Object variable or With block variable not set (Error 91) Please Help

8. Run Time Error 91: Object variable or With Block variable not set

9. VB 5.0 - Error:91 Object Variable Or With Block Variable Not Set

10. Error: Object variable or with block variable not set

11. Object variable or With block variable not set (Error 91)

12. Error 91 Object variable or With-Block, variable not set

 

 
Powered by phpBB® Forum Software