Creating a calculated field in a query with VBA

R

rafik

I need to know the syntax Creating a calculated field in
a query with VBA.
or the syntax to create a query from 2 tables in VBA
thank you in advance.
 
G

Graeme Richardson

Hi, I think you might be aiming at building the querydef up (i.e. supplu
table, supply each field, etc.). You need to supply the entire SQL string!
Something like this.

Dim db As DAO.database: set db= DBEngine.Workspaces(0).Databases(0)
dim qdf As DAO.Querydef
dim strSQL As String

' Note: SQL string not tested (shows formula and joining tables)
strSQL = "SELECT tblMember.Name, DateDiff("yyyy", Date(),
tblMember.DateOfBirth) As Age, tblSubscription.SubscriptionType" & _
"FROM tblMember INNER JOIN tblSubscription ON
tblMember.uidMember = tblSubscription.fkMember"


Set qdf = db.CreateQueryDef("MyQuery", strSQL)
db.QueryDefs.Append qdf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top