Thanks @MajP , I got confused at first ... I copied all the code and paste them on the "on click" event procedure and it was not working and blocked by an error message then I deleted the "Public Sub FilteReport()" at the top and the "End Sub" at the bottom and now it is working perfectly fine just as the way I want it.... I didnt make a brand new database nor import all tables. I also did not compact and repair as the code is already working....Not doing all of these, will it have an effect on the database in the future?Use this instead
Public Sub FilterReport() DoCmd.ShowToolbar "ribbon", acToolbarYes Dim strSql As String Dim i As Integer For i = 1 To Me.ctrSearchResults.ListCount - 1 If strSql = "" Then strSql = "'" & Me.ctrSearchResults.ItemData(i) & "'" Else strSql = strSql & ", '" & Me.ctrSearchResults.ItemData(i) & "'" End If Next i If Not strSql = "" Then strSql = "strVesselName in (" & strSql & ")" 'MsgBox strSql DoCmd.OpenReport "rptVessel", acViewPreview, , strSql DoCmd.Maximize End If End Sub
However. This database is probably corrupt. Make a brand new one. Then import all your tables first. Compact and repair. Then import everything else.
It would not throw any errors. So if you wrote some bad code, it just would not run. No runtime errors happened, no message. It would not catch them on compiling either. That is why it seemed as if it was not running, when in fact it should have thrown an error.