Dim tmpRS As DAO.Recordset
Dim tmpNo As Long
tmpNo = 10
Set tmpRS = CurrentDB.OpenRecordset("SELECT * FROM yourTable WHERE yourField = " & tmpNo)
What do you want it to do?
Currentdb.Querydefs("YourQueryName").sql = "select..."
docmd.openquery "YourQueryName"
Paul's sample will read the query into memory.
You want to create an object to show on screen, which to be honest is a bad idea.
Data should be shown to a user on forms only, here you can control read-only etc.... make it look pretty, etc....
However..... Simply make any query, save it as YourQueryName ... then this should do the trick for you.
Code:Currentdb.Querydefs("YourQueryName").sql = "select..." docmd.openquery "YourQueryName"
Does this actually work?then try
docmd.openquery ("SELECT * FROM yourTable WHERE yourField = " & tmpNo)
Show the code you actually have used so far.I tried that, but do not know how to get the VBA variables into the stored SQL WHere comparison ??
Does this actually work?
Show the code you actually have used so far.
Private Sub Review_Invoice_Click()
Dim tmpRS As DAO.Recordset
Dim customer2 As Variant
Dim PurchaseDate2 As Variant
Dim VendorName2 As Variant
Dim VendorInvoice2 As Variant
customer2 = customer
PurchaseDate2 = PurchaseDate
VendorName2 = VendorName
VendorInvoice2 = VendorInvoice
On Error Resume Next
Currentdb.QueryDefs.Delete "YourQueryName"
Currentdb.CreateQueryDef("YourQueryName", "SELECT * FROM materials WHERE customer = " & Chr(34) & customer2 & Chr(34))
On Error GoTo 0
DoCmd.OpenQuery "YourQueryName"
End Sub
Try this,
Code:Private Sub Review_Invoice_Click() Dim tmpRS As DAO.Recordset Dim customer2 As Variant Dim PurchaseDate2 As Variant Dim VendorName2 As Variant Dim VendorInvoice2 As Variant customer2 = customer PurchaseDate2 = PurchaseDate VendorName2 = VendorName VendorInvoice2 = VendorInvoice On Error Resume Next Currentdb.QueryDefs.Delete "YourQueryName" Currentdb.CreateQueryDef("YourQueryName", "SELECT * FROM materials WHERE customer = " & Chr(34) & customer2 & Chr(34)) On Error GoTo 0 DoCmd.OpenQuery "YourQueryName" End Sub
Does this actually work?
Explain. Is the Data Type of the column number?Syntax error
Not reallywhich you then have to delete which is a pain.
Syntax error
Private Sub Review_Invoice_Click()
Dim tmpRS As DAO.Recordset
Dim customer2 As Variant
Dim PurchaseDate2 As Variant
Dim VendorName2 As Variant
Dim VendorInvoice2 As Variant
[B][COLOR=Red]Dim AQueryDef As QueryDef[/COLOR][/B]
customer2 = customer
PurchaseDate2 = PurchaseDate
VendorName2 = VendorName
VendorInvoice2 = VendorInvoice
On Error Resume Next
CurrentDb.QueryDefs.Delete "YourQueryName"
[B][COLOR=Red]Set AQueryDef =[/COLOR][/B] Currentdb.CreateQueryDef("YourQueryName", "SELECT * FROM materials WHERE customer = " & Chr(34) & customer2 & Chr(34))
On Error GoTo 0
DoCmd.OpenQuery "YourQueryName"
End Sub