Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a Make-Table Query in VBA 1

Status
Not open for further replies.

cwadams

Technical User
Apr 9, 2007
26
US
In Access, Using VBA Only, I am trying to write A Make-Table Query from a table named CompSales INTO a table named Temp using conditions from a form, and then get a count of records. If I write the query in design view it works, but coding in VBA it does not return a record count or update my table called Temp. Suggestions?
'------------------
Option Explicit
Dim X As Integer
Dim FirstPull_Cnt As Integer
Dim strSQL As String

Private Sub FirstPull()

strSQL = "SELECT CompSales.Stat, CompSales.Property, CompSales.[Nbh Code] INTO Temp" & _
"FROM CompSales" & _
"HAVING (((CompSales.Property) Not Like [Forms]![frmSubject]![Property]) AND" & _
"(CompSales.[Stat]) Is Not Null) AND" & _
"((CompSales.[Nbh]) Like [Forms]![frmSubject]![Nbh])"

X = DCount("[Property]", "Temp")
FirstPull_Cnt = X
End Sub
 
Code:
Private Sub FirstPull()

    strSQL = "SELECT CompSales.Stat, CompSales.Property, CompSales.[Nbh Code] INTO Temp" & _
            "FROM CompSales" & _
            "HAVING (((CompSales.Property) Not Like [Forms]![frmSubject]![Property]) AND" & _
            "(CompSales.[Stat]) Is Not Null) AND" & _
            "((CompSales.[Nbh]) Like [Forms]![frmSubject]![Nbh])"
   [b] DoCmd.RunSQL strSQL[/b]
    X = DCount("[Property]", "Temp")
    FirstPull_Cnt = X
End Sub

________________________________________________________
Zameer Abdulla
Help to find Missing people
 
I keep getting: Run-time error 3067;
Query input must contain at least one table or query.

Am I missing something with the DoCmd.RunSQL strSQL statement?
 
Thanks ZmrAbdulla. Got it fixed. Used Debug.print strSQl to see my errors. Forum is closed.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top