Creating a calculated field in a query with VBA

  • Thread starter Thread starter rafik
  • Start date Start date
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.
 
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
 
Back
Top