Question : Example SQL Select Statement VBA Code

I've been trying to compose a VBA Select Statement in Code in Access 2007 without Success. I have been trying very simple queries and from all of online examples, It's always either complaining of a variable I have set incorrectly or something I do not have decalred.  Can someone post an example of a way to write a VBA select Statement to return data from a table and display it in message box?

Example Concept:
Dim vFirstName as String
Select tblName.FirstName from tblContactNames WHERE vFirstName
MsgBox ("First name is " + vFirstName)

I"m new to VBA and Access and an old school C++ programmer, so I'm starting out.

Your help is appreciated!!
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
I've tried this code:
 
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim intResult As Integer
Dim strSQL As String
 
strSQL = "SELECT * FROM tblContactInfo WHERE tblContactInfo.FirstName = Michelle"
Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)
 
'intResult = rs("RecordCount")
rs.Close
db.Close

Answer : Example SQL Select Statement VBA Code

For some odd reason it's named Last Name so when I change the code to show:
strLastName = rs!Last Name

it's throwing a Synax Error (doesn't like the space) is there a way to declare the filed with the space in the name?
Thank you Capricorn1
Random Solutions  
 
programming4us programming4us