There really isn't any direct relation between SQL and VBA. I could write this:
Code:
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
'Let's assume that CN is a connection to an MDB
'file we've already opened.
'ADO is passing on the request to retrieve data to
'the JET database engine. JET understands SQL, so we
'are giving it an SQL statement. VBA doesn't understand
'SQL, this string is meaningless to it.
rs.Open "SELECT LastName FROM Employees", CN
'Now that Jet has retrieved the data for us, let's do
'whatever we oringally wanted it for - let's put it
'in a textbox
txtName.Text = rs("LastName")
Let me say again, they are two different things. SQL doesn't need VBA to exist, and VBA doesn't need SQL. SQL is used by databases, so if in my VBA program I need something from the database, I connect to it and in the language it understands (SQL) I request the information.
The "bridge" in this case are the ADO objects.
If my programming language was C#, I would be using ADO.NET objects, which despite the name simularity are quite different from ADO. In C#, I would be working with DataSets, DataTables, DataRows, etc. instead of recordsets. But ultimately, somewhere in my C# code I would be passing one of the ADO.NET objects the exact same SQL string, i.e. "SELECT LastName FROM Employees"
Code:
// Again, let's assume connection is already open
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandText = "[COLOR=red]SELECT LastName FROM Employees[/color]";
cm.CommandType = CommandType.Text;
using (SqlDataReader dr = new SqlDataReader(cm.ExecuteReader()))
{
dr.Read();
txtName.Text = dr.GetString("LastName");
}
}
Looks quite different from VBA, doesn't it? But notice that the SQL statement is
exactly the same. Just like VBA, C# has no notion of what SQL is. It is just blindly passing the string to the database engine.
The art of programming is often an exercise in dividing the work into components. If it's done well, the different components are black boxes to each other. The components collaborate together, but do not know how each does its work. The programming language (VBA, C#, etc.) has absolutely no awareness of SQL. You as the programmer hopefully have some idea what it means, but it is gibberish to the programming language.
What I suggest is you start working through one of your books in the language of your choice (I guess it's VB or VBA, you might want to think about VB.NET or C#). If the book is any good, it will have at least one chapter on working with databases. Hopefully at that point you will have realized that the programming language is just one way to interface with the database.