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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Creation

Status
Not open for further replies.

thegameoflife

Programmer
Dec 5, 2001
206
US
Is it possible to write code in VBA to create a query and have it appear under the query tab in Access.
 
Const conBtns As Integer = vbYesNo + vbExclamation + vbDefaultButton2 + vbApplicationModal
lcErr_Message = ""
lcQueryName = "Temp"
lcFields = "SELECT * FROM qry_FundsTransfer_Dump "
lcWhere = "WHERE ENTERDATE = #" & Me.cbo_Value_Date.Value & "#"
lcSQL = lcFields & lcWhere

'Error Checking Section
If Me.cbo_Value_Date.Value = "" Or IsNull(Me.cbo_Value_Date.Value) Then
MsgBox ("Please Select a Value Date")
Exit Sub
End If

For Each lc_Query In lc_Db.QueryDefs
If Trim(lc_Query.Name) = Trim(lcQueryName) Then
' Delete Existing Query! or ADD Prompt asking
'if they wish to delete first!!!!
lc_Db.QueryDefs.Delete (lcQueryName)
lc_Db.QueryDefs.Refresh
End If
Next lc_Query

Set lc_Query = lc_Db.CreateQueryDef(lcQueryName, lcSQL)
lc_Db.QueryDefs.Refresh
lc_Db.Close Steve Medvid
"IT Consultant & Web Master"
e-Mail: Stephen_Medvid@GMACM.com

Chester County, PA Residents
Please Show Your Support...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top