Touni102
05-13-2009, 06:14 AM
Reposting this in a new thread - old thread was marked as solved but this is still a problem.
Ok.... i thought this problem was solved. I got far though. My sql string is generating correctly and the data displays when you open the Query directly. However in my form when I interact with the controls, that's when the Sql is Updated, and it should also update the subform too. I have done a requery on the subform before, leading me to think that once I get the sql down this is solved.
Anyway this is what i have:
Function UpdateSQL()
Dim varItem As Variant
Dim whereClause As String
Dim negator As String
If cbNOT.Value = 0 Then
negator = ""
Else
negator = "NOT "
End If
For Each varItem In lbContains.ItemsSelected
whereClause = whereClause & " OR [Computer Software].ProgramName='" & lbContains.ItemData(varItem) & "'"
Next varItem
If Len(whereClause) = 0 Then
whereClause = ""
Else
whereClause = " AND " & negator & "(" & Right(whereClause, Len(whereClause) - 4) & ")"
End If
Dim sqlString As String
sqlString = "SELECT [Computer Summary].ComputerName, [Computer Summary].Info, [Computer Summary].Active, [Computer Software].ProgramName, [Computer Software].Version, [Computer Software].InstallDate "
sqlString = sqlString & "FROM [Computer Summary], [Computer Software] WHERE [Computer Summary].ComputerName=[Computer Software].ComputerName" & whereClause
MsgBox sqlString
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Set db = CurrentDb
Set qdf = db.QueryDefs("Advanced Query")
qdf.SQL = sqlString
Set qdf = Nothing
Set db = Nothing
Forms![Advanced Search]![tblResult].Requery
End Function
The subforms data source is "Advanced Query" which gets it's SQL updated from this code here, with the help of the link supplied above - thanks. When I change the checkbox or select a new selection this function is called. However, the Requery does nothing. I just want to update the query in the subform. Also, i dunno why but there is a bug - when I select only one item in the list box lbContains, lbContains.SelectedItems shows up with nothing...
I'm so close to finishing this but so far from knowing what to do.... Any help again is appreciated.
Ok.... i thought this problem was solved. I got far though. My sql string is generating correctly and the data displays when you open the Query directly. However in my form when I interact with the controls, that's when the Sql is Updated, and it should also update the subform too. I have done a requery on the subform before, leading me to think that once I get the sql down this is solved.
Anyway this is what i have:
Function UpdateSQL()
Dim varItem As Variant
Dim whereClause As String
Dim negator As String
If cbNOT.Value = 0 Then
negator = ""
Else
negator = "NOT "
End If
For Each varItem In lbContains.ItemsSelected
whereClause = whereClause & " OR [Computer Software].ProgramName='" & lbContains.ItemData(varItem) & "'"
Next varItem
If Len(whereClause) = 0 Then
whereClause = ""
Else
whereClause = " AND " & negator & "(" & Right(whereClause, Len(whereClause) - 4) & ")"
End If
Dim sqlString As String
sqlString = "SELECT [Computer Summary].ComputerName, [Computer Summary].Info, [Computer Summary].Active, [Computer Software].ProgramName, [Computer Software].Version, [Computer Software].InstallDate "
sqlString = sqlString & "FROM [Computer Summary], [Computer Software] WHERE [Computer Summary].ComputerName=[Computer Software].ComputerName" & whereClause
MsgBox sqlString
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Set db = CurrentDb
Set qdf = db.QueryDefs("Advanced Query")
qdf.SQL = sqlString
Set qdf = Nothing
Set db = Nothing
Forms![Advanced Search]![tblResult].Requery
End Function
The subforms data source is "Advanced Query" which gets it's SQL updated from this code here, with the help of the link supplied above - thanks. When I change the checkbox or select a new selection this function is called. However, the Requery does nothing. I just want to update the query in the subform. Also, i dunno why but there is a bug - when I select only one item in the list box lbContains, lbContains.SelectedItems shows up with nothing...
I'm so close to finishing this but so far from knowing what to do.... Any help again is appreciated.