Solved

delete query error on microsoft access form

Posted on 2010-11-11
5
242 Views
Last Modified: 2012-06-21
Hi Experts,

I have a delete button on a form that allows the user to delete client records from 7 different tables so we don't have any straggling data, but i get an error if one of the tables doesn't have any data containing that client id which is what the query picks up to determine which fields to delete from the tables.  The error is a runtime error 3075, "Syntax error in date in query expression 'ClientID=#Deleted'.  Below is the code.  The client i tried to delete has a record in tblClients but no records in any of the other tables.  Thanks :-)

Laura
Private Sub cmdDeleteNew_Click()



    'make sure user wants to delete / sets commands for user answer

     Select Case MsgBox("Are you sure you want to delete this client?", vbYesNoCancel + vbQuestion)

     

        Case vbNo

            Me.Refresh

        Case vbYes

            'delete all records pertaining to a client

            CurrentDb.Execute "Delete * FROM tblClients WHERE ClientID=" & Me.lstNewClients.Column(0)

            CurrentDb.Execute "Delete * FROM tblASC WHERE ClientID=" & Me.lstNewClients.Column(0)

            CurrentDb.Execute "Delete * FROM tblAddVerify WHERE ClientID=" & Me.lstNewClients.Column(0)

            CurrentDb.Execute "Delete * FROM tblRFI WHERE ClientID=" & Me.lstNewClients.Column(0)

            CurrentDb.Execute "Delete * FROM tblCaseNotes WHERE ClientID=" & Me.lstNewClients.Column(0)

            CurrentDb.Execute "Delete * FROM tblCaseNotesVerify WHERE ClientID=" & Me.lstNewClients.Column(0)

            CurrentDb.Execute "Delete * FROM tblCaseNotesRFI WHERE ClientID=" & Me.lstNewClients.Column(0)

            Me.lstNewClients.Requery

        Case vbCancel

            Me.Refresh

        

     End Select

     

End Sub

Open in new window

0
Comment
Question by:linbayzak
  • 3
  • 2
5 Comments
 

Author Comment

by:linbayzak
ID: 34114812
could it be because of the order of the delete, like maybe i should delete from the main client table last?  thanks
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 34114955
<could it be because of the order of the delete, like maybe i should delete from the main client table last?> that should be the case,

but are you sure that the error is coming from those codes?

can you verify which line is raising the error.
0
 

Author Comment

by:linbayzak
ID: 34114992
yes, it breaks on the second line of the delete execute

 CurrentDb.Execute "Delete * FROM tblASC WHERE ClientID=" & Me.lstNewClients.Column(0)
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 34115088
the error  could be the value from the lstNewClients listbox.

what is the rowsource of the list box lstNewClients?


try this codes


Private Sub cmdDeleteNew_Click()

dim varID as long

varID=me.lstNewClients.column(0)

    'make sure user wants to delete / sets commands for user answer

     Select Case MsgBox("Are you sure you want to delete this client?", vbYesNoCancel + vbQuestion)

     

        Case vbNo

            Me.Refresh

        Case vbYes

            'delete all records pertaining to a client

            CurrentDb.Execute "Delete * FROM tblClients WHERE ClientID=" & varID

            CurrentDb.Execute "Delete * FROM tblASC WHERE ClientID=" & varID

            CurrentDb.Execute "Delete * FROM tblAddVerify WHERE ClientID=" & varID

            CurrentDb.Execute "Delete * FROM tblRFI WHERE ClientID=" & varID

            CurrentDb.Execute "Delete * FROM tblCaseNotes WHERE ClientID=" & varID

            CurrentDb.Execute "Delete * FROM tblCaseNotesVerify WHERE ClientID=" & varID

            CurrentDb.Execute "Delete * FROM tblCaseNotesRFI WHERE ClientID=" & varID

            Me.lstNewClients.Requery

        Case vbCancel

            Me.Refresh

        

     End Select

     

End Sub

Open in new window

0
 

Author Closing Comment

by:linbayzak
ID: 34115392
awesome, thanks :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
DSum for Access 6 46
Sum Multiple Columns in Access Query 5 50
Prevent use of Microsoft Office application 9 53
Access Excel export not behaving 2 25
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now