List Box (1 Viewer)

cbabi2

Member
Local time
Today, 13:16
Joined
Sep 29, 2014
Messages
34
Use this instead
Code:
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.
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?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:16
Joined
May 21, 2018
Messages
6,443
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?
Your DB was exhibiting some very strange behavior. I could write an incorrect line of code and it would not cause an error. It just did nothing nor would it catch this in compiling. Personally, I would not go any farther without decompiling/recompiling and then importing into a clean DB. If you are not seeing this behavior anymore than maybe it is OK. This is not a big deal and takes little time once you do it once. I continually make backups as I develop and then make new fresh databases. It is the same as your computer starting to act weird and you do a hard reboot to clean out the junk.
 

cbabi2

Member
Local time
Today, 13:16
Joined
Sep 29, 2014
Messages
34
Thanks @MajP for the advice..
 

Users who are viewing this thread

Top Bottom