Microsoft Access Database Engine Cannot Find the Input Table or Query (1 Viewer)

JithuAccess

Member
Local time
Yesterday, 21:45
Joined
Mar 3, 2020
Messages
264
Hello Guys,

This is my Code:

Dim db As Database
Dim rst As Recordset
Dim STRSQL As String

Set db = CurrentDb()

STRSQL = "Select [Table1.ID] from [Table1];"

Set rst = db.OpenRecordset(STQSQL)

I am getting an error message like:

1612455472475.png


I have this Table1 in my Database. I have no idea why I am getting this Error. Could you kindly let me know what is the Error.

Thanks
 

Gasman

Enthusiastic Amateur
Local time
Today, 04:45
Joined
Sep 21, 2011
Messages
8,493
Look at how you spell STRSQL :(

You should have Option Explicit at the tope of ALL your modules?

That would have highlighted your error?

Also please start using code tags, you have over 100 posts on here, and should know way before now :-(
 

JithuAccess

Member
Local time
Yesterday, 21:45
Joined
Mar 3, 2020
Messages
264
Look at how you spell STRSQL :(

You should have Option Explicit at the tope of ALL your modules?

That would have highlighted your error?

Also please start using code tags, you have over 100 posts on here, and should know way before now :-(

Thanks a lot. There wasn't Option Explicit at the Top of my Code Window. It works perfect when I add this.
 

Gasman

Enthusiastic Amateur
Local time
Today, 04:45
Joined
Sep 21, 2011
Messages
8,493
Thanks a lot. There wasn't Option Explicit at the Top of my Code Window. It works perfect when I add this.
A simple addition of Option Explicit would not fix the error?. It would highlight the error?
 

JithuAccess

Member
Local time
Yesterday, 21:45
Joined
Mar 3, 2020
Messages
264
A simple addition of Option Explicit would not fix the error?. It would highlight the error?
I am not sure about that but this is working perfect now. Before your suggestion for adding Option Explicit I put the Code like this:

Code:
Dim db As Database
Dim rst As Recordset
Dim STRSQL As String

Set db = CurrentDb()

Set rst = db.OpenRecordset(Select [Table1.ID] from [Table1])

End Sub

And this was working.

Thanks
 

Gasman

Enthusiastic Amateur
Local time
Today, 04:45
Joined
Sep 21, 2011
Messages
8,493
You have STRSQL = "Select [Table1.ID] from [Table1];"

and you use Set rst = db.OpenRecordset(STQSQL) :(
 

Users who are viewing this thread

Top Bottom