I have a mainform with a subform.[color=blue]
> The main form has a dropdown box "chooseMont h", in the afterupdate event
> i requery the subform so all records with the same date are viewed.
> Now i only want to print the selected records of the selected month
> Can any one advise on the below[/color]
Below is code i am trying to adapt (Thanks Don)
1.This first part is causing me problems so i have deleted it as it
strikes me that it is looking for a listbox and i have a form with a
subform please correct me if i am wrong as an error appears with the
VarItm.
2.
The other part of the code is what i am working on, my problem is that
Me.choosemonth is giving me an error 3070 does not recognise 200403 as
a valid field .
Where do i get this number from? qryGSTRecieved
PaidMonth: Format([paidDate],"yyyymm ")
This is used in the dropdown box Me.ChooseMonth
--------------------------------------------------------------------------------
Deleted this
Dim ctl As Control
Dim varItm As Variant
Dim strSelected As String
Set ctl = Me.lstTransType
For Each varItm In ctl.ItemsSelect ed
If Len(strSelected ) > 0 Then
strSelected = strSelected & ", " & chr$(39) &
ctl.ItemData(va rItm) & chr$(39)
Else
strSelected = chr$(39) & ctl.ItemData(va rItm) & chr$(39)
End If
Next varItm
'Debug.Print strSelected
--------------------------------------------------------------------------------
Using this
MySql = "" 'Clear the string variable
'Construct the MAIN SQL statement here
MySql = MySql & "SELECT qryGSTRecieved. * FROM qryGSTRecieved "
'Now test for and add the WHERE portion here
If Len(strSelected ) > 0 And InStr(1, strSelected, "All") = 0 Then
MySql = MySql & "WHERE (((qryGSTReciev ed.PaidDate)In( "
MySql = MySql & strSelected
MySql = MySql & "))) "
End If
'Again, test for and add the ORDER BY here.
If Not IsNull(Me.choos eMonth) Then
MySql = MySql & "ORDER BY "
MySql = MySql & Me.chooseMonth
End If
'Finally, "close out" the SQL string using the semi-colon
MySql = MySql & "; "
'Check the resulting SQL string.
'If an error is displayed, you can copy the SQL string from the debug
window
'into a new query in order to help determine why it isn't working
'Debug.Print MySQL
'Setting the subform's Recordsource here automatically updates the
display.
'No need to requery the subform.
Me.fsubGSTRecie ved.Form.Record Source = MySql
Set ctl = Nothing
End Sub
=============== =============
> The main form has a dropdown box "chooseMont h", in the afterupdate event
> i requery the subform so all records with the same date are viewed.
> Now i only want to print the selected records of the selected month
> Can any one advise on the below[/color]
Below is code i am trying to adapt (Thanks Don)
1.This first part is causing me problems so i have deleted it as it
strikes me that it is looking for a listbox and i have a form with a
subform please correct me if i am wrong as an error appears with the
VarItm.
2.
The other part of the code is what i am working on, my problem is that
Me.choosemonth is giving me an error 3070 does not recognise 200403 as
a valid field .
Where do i get this number from? qryGSTRecieved
PaidMonth: Format([paidDate],"yyyymm ")
This is used in the dropdown box Me.ChooseMonth
--------------------------------------------------------------------------------
Deleted this
Dim ctl As Control
Dim varItm As Variant
Dim strSelected As String
Set ctl = Me.lstTransType
For Each varItm In ctl.ItemsSelect ed
If Len(strSelected ) > 0 Then
strSelected = strSelected & ", " & chr$(39) &
ctl.ItemData(va rItm) & chr$(39)
Else
strSelected = chr$(39) & ctl.ItemData(va rItm) & chr$(39)
End If
Next varItm
'Debug.Print strSelected
--------------------------------------------------------------------------------
Using this
MySql = "" 'Clear the string variable
'Construct the MAIN SQL statement here
MySql = MySql & "SELECT qryGSTRecieved. * FROM qryGSTRecieved "
'Now test for and add the WHERE portion here
If Len(strSelected ) > 0 And InStr(1, strSelected, "All") = 0 Then
MySql = MySql & "WHERE (((qryGSTReciev ed.PaidDate)In( "
MySql = MySql & strSelected
MySql = MySql & "))) "
End If
'Again, test for and add the ORDER BY here.
If Not IsNull(Me.choos eMonth) Then
MySql = MySql & "ORDER BY "
MySql = MySql & Me.chooseMonth
End If
'Finally, "close out" the SQL string using the semi-colon
MySql = MySql & "; "
'Check the resulting SQL string.
'If an error is displayed, you can copy the SQL string from the debug
window
'into a new query in order to help determine why it isn't working
'Debug.Print MySQL
'Setting the subform's Recordsource here automatically updates the
display.
'No need to requery the subform.
Me.fsubGSTRecie ved.Form.Record Source = MySql
Set ctl = Nothing
End Sub
=============== =============
Comment