Object Required compile error

D

D. Stacy

I need some help with the syntex as this is hitting the error on the Set
statement:


Private Sub cmdDataTransform_Click()
' Run qry DataTransform on table "OR_Record"

Dim strTableName As String
Dim db As Database
Set strTableName = db(OR_Record)

On Error Resume Next

If TableExists(strTableName) Then
DoCmd.DeleteObject acTable, "OR_RECORD"

End If

End Sub


The purpose of this code is just to delete a table, if it exists.
 
J

Jack Leach

And the variable strTableName cannot be "set"... its a String, not an Object
(you only Set objects)

Some more examples of the difference between objects and datatypes

Dim obj As Form
Dim obj As Database
Dim obj As Recordset
Dim obj As TableDef
Dim obj As Report
Dim obj As CommandBar
Dim obj As Control

All of the above are various types of objects, which all require them to be
Set:

Set obj = CurrentDb.TableDefs("OR_Record")

The above list is by no means complete... there are hundreds (thousands?) of
different types of objects that require "setting"

Regular old datatypes, on the other hand, cannot be "set". You just give
them a value with an = sign.

Dim MyString As String
Dim MyByte As Byte
Dim MyLong As Long
Dim MyDouble As Double
Dim MyBool As Boolean

MyString = "thisthatandsomeotherthing"
MyByte = 1
MyLong = 6548214
MyDouble = 6542.5481
MyBool = False


The list of datatypes isn't complete, but there's only a couple missing.
Not nearly as many as there are objects, although these tend to be used far
more often.


hth
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top