Avatar of nlouder
nlouder
 asked on

vba query using multi field listbox

I have a access form with two list boxes called Available and Chosen the Available list box is populated with 3 fields (Agcno (number), Agency(text) & State(text) from the table TBLAgency.  When a record is selected from the Available listbox and added to the Chosen listbox I would like to update a field called Flag1 for the selected record in my table with a "false" value.  I have used the following vba code which works fine in another database using a single field listbox but is erroring out on the query using the 3 fields listbox.

Private Sub Add_Click()
   
    If Available.ItemsSelected.Count = 1 Then
        CurrentDb.Execute ("UPDATE TBLAgency SET TBLAgency.FLAG1 = False " & _
        "WHERE TBLAgency.AGCNO AND TBLAgency.AGENCY AND TBLAgency.CITY ='" & Available & "';")
        Available.Requery
        Chosen.Requery
                   
    End If
End Sub

Any ideas or solutions?
Microsoft Access

Avatar of undefined
Last Comment
Mike Eghtebas

8/22/2022 - Mon
peter57r

Hi nlouder,

Is this complete

>       "WHERE TBLAgency.AGCNO AND TBLAgency.AGENCY AND TBLAgency.CITY
> ='" & Available & "';")

This is the same as:

      "WHERE TBLAgency.AGCNO = true AND TBLAgency.AGENCY = true AND TBLAgency.CITY ='" & Available & "';")

Is that what you mean?

Pete
ASKER CERTIFIED SOLUTION
Leigh Purvis

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
nlouder

ASKER
LPurvis:

It is City I'm trying to match on sorry for the error.  You're solution works great.
Mike Eghtebas

try:

Private Sub Add_Click()
   
    If Available.ItemsSelected.Count = 1 Then
        CurrentDb.Execute ("UPDATE TBLAgency SET TBLAgency.FLAG1 = False " & _
        "WHERE TBLAgency.AGCNO=" & Available.column(0) & ", AND TBLAgency.AGENCY ='" & Available.column(1) & ", AND TBLAgency.CITY ='" &   Available.column(2) & "';")
        Available.Requery
        Chosen.Requery
                   
    End If
End Sub

Mike
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck