We help IT Professionals succeed at work.
Get Started

Add items to listbox upon opening form.

stephenlecomptejr
on
290 Views
Last Modified: 2016-08-29
I'm unable to display the values in a listbox upon the database opening up.  Please note code below and sample.  Please tell me how I can rearrange my syntax or recordsource to display the values correctly.

https://filedb.experts-exchange.com/incoming/ee-stuff/8155-sample_listbox.mdb 

I just want either someone to fix the code in the sample or tell me directly how it should properly otherwise.  Have to get out something very soon.
Option Compare Database
Option Explicit

Private Sub cmdAdd_Click()
  lstSection.AddItem Item:=New_Section_Value
End Sub

Private Sub Form_Load()
  
End Sub

Private Sub Form_Open(Cancel As Integer)

  Call Set_Combos
  Call Set_ListBoxes
  
End Sub

Private Sub Set_Combos()
  cboVolume.Value = Nz(cboVolume.Column(0, 0), 0)
End Sub

Private Sub Set_ListBoxes()
  Call Fill_Section_ListBox
End Sub

Private Sub Fill_Section_ListBox()
  
  Dim lVol As Long
  lstSection = ""
  lVol = Nz(cboVolume.Column(0, 0), 0)
  Dim sSQL As String
  sSQL = "SELECT [SectionName], [VolumeID] FROM [tblSections] WHERE [VolumeID] = " & lVol & " ORDER BY [SectionName] "
  Dim rs As DAO.Recordset
  Set rs = CurrentDb.OpenRecordset(sSQL)
  Do Until rs.EOF
    lstSection.AddItem Nz(rs.Fields(0), "")
    rs.MoveNext
  Loop
  rs.Close
  Set rs = Nothing
  Me.Refresh
  DoEvents
  
End Sub

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Top Expert 2016
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE