[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

delete query error on microsoft access form

Posted on 2010-11-11
5
Medium Priority
?
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

656 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