P
pahan
Hello all!
I have an Access form and I need to issue a query with two parameters based
on values entered in a form. I have found an example in Access's help which
looked like this (modified to suit my task):
Private Sub GenerateReport()
Dim db As Database
Dim q1 As QueryDef
Dim q1_res As Recordset
Dim q1_text As String
Set db = CurrentDb
q1_text = "PARAMETERS [Number] Integer, [Time] Datetime;SELECT
Count(*) FROM
WHERE [num_column]=[Number] AND [time_column]=[Time];"
Set q1 = db.CreateQueryDef("", q1_text)
For i = 0 To ListBox6.ItemsSelected.Count - 1
For j = 0 To ListBox8.ItemsSelected.Count - 1
q1.Parameters![Number] = ListBox6.ItemsSelected.Item(i)
q1.Parameters![Time] = ListBox8.ItemsSelected.Item(j)
Set q1_res = q1.OpenRecordSet(dbOpenSnapshot)
' Processing result here
q1_res.Close
Next j
Next i
End Sub
But when I run it, I got an error "User-defined type not defined" at the
first line "Dim db As Database". From (very bad) Access help I found that the
above code is applicable only to remote datasources connected to Access (am I
right?). What is the right way to issue a SQL query to Access table from
Access form?
Greatly thanks!
I have an Access form and I need to issue a query with two parameters based
on values entered in a form. I have found an example in Access's help which
looked like this (modified to suit my task):
Private Sub GenerateReport()
Dim db As Database
Dim q1 As QueryDef
Dim q1_res As Recordset
Dim q1_text As String
Set db = CurrentDb
q1_text = "PARAMETERS [Number] Integer, [Time] Datetime;SELECT
Count(*) FROM
Set q1 = db.CreateQueryDef("", q1_text)
For i = 0 To ListBox6.ItemsSelected.Count - 1
For j = 0 To ListBox8.ItemsSelected.Count - 1
q1.Parameters![Number] = ListBox6.ItemsSelected.Item(i)
q1.Parameters![Time] = ListBox8.ItemsSelected.Item(j)
Set q1_res = q1.OpenRecordSet(dbOpenSnapshot)
' Processing result here
q1_res.Close
Next j
Next i
End Sub
But when I run it, I got an error "User-defined type not defined" at the
first line "Dim db As Database". From (very bad) Access help I found that the
above code is applicable only to remote datasources connected to Access (am I
right?). What is the right way to issue a SQL query to Access table from
Access form?
Greatly thanks!