ADO, VBA, & Hyphens.

asather

Registered User.
Local time
Today, 14:19
Joined
Dec 31, 2007
Messages
22
Does VBA not like hyphens in table names?

This works:
Public Sub myTest()

Dim v() As Variant

Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset

Dim thistest As String
thistest = "tblMembershipFeeCategory"
rs.Open "SELECT * FROM " & thistest, CurrentProject.Connection, adOpenDynamic, adLockReadOnly
v = rs.GetRows
rs.Close

End Sub

...But add a hyphen to the table name in the code and in the database....And it doesn't....
Public Sub myTest()

Dim v() As Variant

Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset

Dim thistest As String
thistest = "tblMembershipFee-Category"
rs.Open "SELECT * FROM " & thistest, CurrentProject.Connection, adOpenDynamic, adLockReadOnly
v = rs.GetRows
rs.Close

End Sub
 
You should never use hypens anywhere.
Always use underscores eg. tblMembershipFee_Category.
 
...I could smack my database professor.
 

Users who are viewing this thread

Back
Top Bottom