AndyShuter
Registered User.
- Local time
- Today, 19:20
- Joined
- Mar 3, 2003
- Messages
- 151
Could somebody pls help me with this code?
I am trying to create a query based on the values of a listbox, buy get the following error
Compile Error
"User Defined Type Not Defined"
I think it's something to do with the bits in orange?
Dim MyDB As DAO.Database
Dim qdf As DAO.QueryDef
Dim i As Integer, strSQL As String
Dim strWhere As String, strIN As String
Dim flgAll As Boolean
Set MyDB = CurrentDb()
strSQL = "SELECT * FROM CurrentStatus"
'create the IN string by looping thru the listbox
For i = 0 To Me.List139.ListCount - 1
If Me.List139.Selected(i) Then
If Me.List139.Column(0, i) = "All" Then
flgAll = True
End If
strIN = strIN & "'" & Me.List139.Column(0, i) & "',"
End If
Next i
'create the WHERE string, stripping off the last comma of the IN string
strWhere = " WHERE [CurrentStatus] in (" & Left(strIN, Len(strIN) - 1) & ")"
'if "All" was selected, don't add the WHERE condition
If Not flgAll Then
strSQL = strSQL & strWhere
End If
MyDB.QueryDefs.Delete "qryLog1"
Set qdf = MyDB.CreateQueryDef("qryLog1", strSQL)
Many Thanks
Andy
I am trying to create a query based on the values of a listbox, buy get the following error
Compile Error
"User Defined Type Not Defined"
I think it's something to do with the bits in orange?
Dim MyDB As DAO.Database
Dim qdf As DAO.QueryDef
Dim i As Integer, strSQL As String
Dim strWhere As String, strIN As String
Dim flgAll As Boolean
Set MyDB = CurrentDb()
strSQL = "SELECT * FROM CurrentStatus"
'create the IN string by looping thru the listbox
For i = 0 To Me.List139.ListCount - 1
If Me.List139.Selected(i) Then
If Me.List139.Column(0, i) = "All" Then
flgAll = True
End If
strIN = strIN & "'" & Me.List139.Column(0, i) & "',"
End If
Next i
'create the WHERE string, stripping off the last comma of the IN string
strWhere = " WHERE [CurrentStatus] in (" & Left(strIN, Len(strIN) - 1) & ")"
'if "All" was selected, don't add the WHERE condition
If Not flgAll Then
strSQL = strSQL & strWhere
End If
MyDB.QueryDefs.Delete "qryLog1"
Set qdf = MyDB.CreateQueryDef("qryLog1", strSQL)
Many Thanks
Andy