Look at table and verify records exists

Hi,

I have a form which I want to run an append query if records exists in a temp table.

I saw some code in another database and I trimmed it up to the following, however I"m not certainif I'm on the right track here.  I can't use the ADODB statement in my version of Access 2010 as it doesn't exists.

Can someone advise me the best way to see if records do exists in a table and perhaps pass a True or False variable or soemother indicator?

Public Function chk_table()
Dim rs As ADODB.Recordset
Dim stSQL As String

stSQL = "select * from " & mytable

Set rs = New ADODB.Recordset
rs.Open stSQL, Application.CodeProject.Connection, adOpenStatic, adLockOptimistic

If (rs.RecordCount = 0) Then
   'do nothing
Else
   'do something
End if
End Function
MCaliebeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Surone1Commented:
Public Function chk_table(mytable as String)
Dim rs As ADODB.Recordset
Dim stSQL As String

stSQL = "select * from " & mytable

Set rs = New ADODB.Recordset
rs.Open stSQL, Application.CodeProject.Connection, adOpenStatic, adLockOptimistic

If rs.Eof= true Then
   'no record found, return false
chk_table = false
Else
   'record(s) found, return true
chk_table = true
End if
End Function





msgbox chk_table("table_name")
0
Rey Obrero (Capricorn1)Commented:

if dcount("*", "tempTable",<criteria>)> 0 then
   ' do something
end if

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Surone1Commented:
just to be sure to hanlde spaces/reserved words in table names:

stSQL = "select * from [" & mytable & "]"
0
Surone1Commented:
or what cap said..
0
MCaliebeAuthor Commented:
Simple solution.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.