2008-12-23 106 views

回答

23

一個模糊的答案模糊的問題:)

strSQL="SELECT * FROM tblT WHERE ID =" & Forms!Form1!txtID 

Set qdf=CurrentDB.CreateQueryDef("NewQuery",strSQL) 
DoCmd.OpenQuery qdf.Name 
+0

唉我一直在努力的事情與此類似爲過去三小時:(多謝 – 2008-12-24 00:01:55

4

感謝這個答案和一小段代碼。如果有人需要定義中使用的變量數據類型,使用此:

Dim strsql As Variant 
    Dim qdf As QueryDef 
+4

昏暗STRSQL作爲字符串 – Fionnuala 2014-07-11 12:05:34

2
Dim strSql As String 'as already in example 
Dim qdf As QueryDef 'as already in example 

strSql = "SELECT * FROM tblT WHERE ID =" & Forms!Form1!txtID 'as already in example 

On Error Resume Next 
'Delete the query if it already exists 
DoCmd.DeleteObject acQuery, "NewQuery" 

Set qdf = CurrentDb.CreateQueryDef("NewQuery", strSql) 'as already in example 
DoCmd.OpenQuery qdf.Name 'as already in example 

'release memory 
qdf.Close 'i changed qdef to qdf here and below 
Set qdf = Nothing