troubleshooting Question

Trying to write selected values from a listbox to a table

Avatar of SteveL13
SteveL13Flag for United States of America asked on
Microsoft Access
16 Comments2 Solutions103 ViewsLast Modified:
I have the following code in an afterupdate event of a form.  I've tried my best to construct it but am not sure it is right. Three things...

1) Will the code work?
2)  Why am I getting a "Else without If" when I try to compile?
3)  Is the after update event of the form the right place for this?

Here's my code so far:

Private Sub Form_AfterUpdate()

    Dim RS As DAO.Recordset
    Dim varitem As Variant
    Set RS = CurrentDb.OpenRecordset("tblSelectedLoadIDs")
    If DCount("[DASContractNumber]", "tblSelectedLoadIDs", "[DASContractNumber] = " & Forms!frmBillOfLadingSelector!txtDASContractNumber) > 0 Then
        With RS
        For Each varitem In listLoadIDs.ItemsSelected
        RS!SelectedLoadID = Me.listLoadIDs.Column(2)
        RS!DASContractNumber = Me.txtDASContractNumber
        With RS
        For Each varitem In listLoadIDs.ItemsSelected
        RS!DASContractNumber = Me.txtDASContractNumber
        RS!SelectedLoadID = Me.listLoadIDs.Column(2)
        End With
    End If

    Set RS = Nothing

End Sub

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 16 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 16 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros