List Box (1 Viewer)

Gasman

Enthusiastic Amateur
Local time
Today, 21:01
Joined
Sep 21, 2011
Messages
10,860
Are you up to date with service packs?
 

oleronesoftwares

Passionate Learner
Local time
Today, 13:01
Joined
Sep 22, 2014
Messages
1,140
I doubt it, I will do that. Thank you. Will revert back on outcome
 

oleronesoftwares

Passionate Learner
Local time
Today, 13:01
Joined
Sep 22, 2014
Messages
1,140
Hi @Gasman , my system runs on windows 7, while trying to update service packs, am told windows 7 support is over(this I am aware of), and advised to update to another windows version. At least on this system, i want to retain windows 7.
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:01
Joined
Sep 21, 2011
Messages
10,860
Hi @Gasman , my system runs on windows 7, while trying to update service packs, am told windows 7 support is over(this I am aware of), and advised to update to another windows version. At least on this system, i want to retain windows 7.
Not windows service pack, Access/Office service pack (if you can still get it?)
1639418569108.png
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:01
Joined
Sep 21, 2011
Messages
10,860
The latest if 4 holds all previous. I only have sp3 as you can see?
According to Google, sp3 is the latest for 2007, so no idea what you are looking at?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:01
Joined
Feb 19, 2002
Messages
36,914
1. Want it that when I open the form the 1st record on the list is automatically selected
This is wrong! Whatever item was selected originally is what should be selected when the form opens. You do NOT want to modify existing data this way.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:01
Joined
May 21, 2018
Messages
6,443
This is wrong! Whatever item was selected originally is what should be selected when the form opens. You do NOT want to modify existing data this way.
The OP has an unbound listbox so there is no previously selected item. It is a search box.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:01
Joined
May 21, 2018
Messages
6,443
The images are what I demoes showing how you can format a continuous form and code to make it act bound. That was separate from the default choice discussion.
 

cbabi2

Member
Local time
Today, 13:01
Joined
Sep 29, 2014
Messages
34
You should have a PK in the search results somewhere. I used the vesselname since there was none.
Code:
Private Sub frmbutPrintSelected_Click()
  DoCmd.ShowToolbar "ribbon", acToolbarYes
  DoCmd.OpenReport "rptVessel", acViewPreview, , "strVesselName = '" & Me.ctrSearchResults & "'"
  DoCmd.Maximize
End Sub

if you had a numeric PK it would be like
DoCmd.OpenReport "rptVessel", acViewPreview, , "SomePKFieldInReport = " & Me.ctrSearchResults
without single quotes.
You can bind the search form to a hidden field if that is the PK.
Thanks for the code...........my PK is the vesselname, I tried the code but on the print priview its just showing the selected record (1 record) instead of what the results on the search.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:01
Joined
May 21, 2018
Messages
6,443
I thought you wanted the selected record. You want the filtered list?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:01
Joined
May 21, 2018
Messages
6,443
if you want to print the whole filtered set then
Code:
Private Sub frmbutPrintSelected_Click()
  DoCmd.ShowToolbar "ribbon", acToolbarYes
  Dim strSql As String
  Dim i As Integer
  Dim rs As DAO.Recordset
  Set rs = Me.ctrSearchResults.Recordset
  Do While Not rs.EOF
    If strSql = "" Then
      strSql = "'" & rs!strVesselName & "'"
    Else
      strSql = strSql & ", '" & rs!strVesselName & "'"
    End If
    rs.MoveNext
  Loop
  If Not strSql = "" Then
    strSql = "strVesselName in (" & strSql & ")"
    MsgBox strSql
    DoCmd.OpenReport "rptVessel", acViewPreview, , strSql
    DoCmd.Maximize
  End If
End Sub

I would change this to a multiselect listbox, then you can filter but only pick ones you want to print.
 

cbabi2

Member
Local time
Today, 13:01
Joined
Sep 29, 2014
Messages
34
if you want to print the whole filtered set then
Code:
Private Sub frmbutPrintSelected_Click()
  DoCmd.ShowToolbar "ribbon", acToolbarYes
  Dim strSql As String
  Dim i As Integer
  Dim rs As DAO.Recordset
  Set rs = Me.ctrSearchResults.Recordset
  Do While Not rs.EOF
    If strSql = "" Then
      strSql = "'" & rs!strVesselName & "'"
    Else
      strSql = strSql & ", '" & rs!strVesselName & "'"
    End If
    rs.MoveNext
  Loop
  If Not strSql = "" Then
    strSql = "strVesselName in (" & strSql & ")"
    MsgBox strSql
    DoCmd.OpenReport "rptVessel", acViewPreview, , strSql
    DoCmd.Maximize
  End If
End Sub

I would change this to a multiselect listbox, then you can filter but only pick ones you want to print.
Thanks for the response... I tried the code, opened the form and try to search for "en" and this message pops up

1639484244084.png


after I clicked "Ok" it brings me to the print preview of the search result




after I close the print preview I tried to make another search and click the "Print Selected" button again but this time nothing happens, the button stopped working....
what should I do so that the pop up message wont show.... and so that "Print Selected" button will still work on the succeeding searches
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:01
Joined
May 21, 2018
Messages
6,443
Sorry I put that in for testing. Just delete that line of code. It shows how you can write a search string for multiple items
Code:
where strVesselName IN ('Name1', 'Name2', 'Name3')
 

cbabi2

Member
Local time
Today, 13:01
Joined
Sep 29, 2014
Messages
34
Sorry I put that in for testing. Just delete that line of code. It shows how you can write a search string for multiple items
Code:
where strVesselName IN ('Name1', 'Name2', 'Name3')
Thanks but I cant find the line of code to delete...... I tried do delete some code but it messed the process.... and what should I change so that the "Print Selected" button will work on succeeding searches
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:01
Joined
May 21, 2018
Messages
6,443
Msgbox
Is the code to show a message box. Look for that line. I have to see what would cause not to run subsequent times.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:01
Joined
May 21, 2018
Messages
6,443
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.
 

Users who are viewing this thread

Top Bottom