Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete from list box based on two columns 1

Status
Not open for further replies.

Eprice

Technical User
May 6, 2003
209
US
Hi,
I have a list box with no primary key. Fields in table are Branch and ReviewYear - both text. The table I want to delete records from could have 20 records matching Branch and ReviewYear selected in the list box. The code I have tried gives me an error "Invalid use of '.', '!' or ()in query expression.....
Here is the code:

DoCmd.RunSQL "DELETE * FROM [tbl PriorUndReview] WHERE [tbl PriorUndReview].Branch=" _
& [Forms]![frm PurgeReview]![lstNew].Column(0) _
& " AND [tbl PriorUndReview].ReviewYear=" _
& [Forms]![frm PurgeReview]![lstNew].Column(1)

I am not good with sql and not sure if its because I am trying to use the column() of list box or if I am missing quotes somewhere. Thanks Lisa
 
G'day Lisa,

Code:
DoCmd.RunSQL "DELETE * FROM [tbl PriorUndReview] WHERE [tbl PriorUndReview].Branch= [red]'[/red]" _
& [Forms]![frm PurgeReview]![lstNew].Column(0) _
& "[red]'[/red] AND [tbl PriorUndReview].ReviewYear=[red]'[/red]" _
& [Forms]![frm PurgeReview]![lstNew].Column(1) [red]& "'";[/red]

the above asumes review year is text, if it's aa date then you'll need to use an In or Between statement to capture it nd use # as delimiters

Hope this helps. happy weekend!

JB
 
Thanks, JB that worked but I had to take the colon off at the end. Lisa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top