Please help with delete query

Carl Foster

Registered User.
Local time
Today, 09:32
Joined
May 29, 2006
Messages
72
[SOLVED!]Please help with delete query

:confused:

Hi all

I've created a delete query and I wanted to run it with the RunSQL command.

Here is the code:

Code:
Private Sub btnDelete_Click()

RoundName.SetFocus

Dim strRoundName As String
strRoundName = Me.RoundName.Text
Dim SQL As String

SQL = "DELETE Rounds.RoundName" & _
    "FROM Rounds" & _
    "WHERE Rounds.RoundName ='strRoundName'"
    
   DoCmd.RunSQL SQL
    
End Sub

When I click the delete button, it comes up with this error:

Run-time error '3075':

Syntax error (missing operator) in query expression
'Rounds.RoundNameFROM RoundsWHERE Rounds.RoundName='strRoundName".

I'm not sure where the missing syntax is for this query, could anyone help please.

Thanks
Carl
 
Last edited:
Hi -

Where does ='strRoundName' come into the picture and what does it stand for?
You haven't defined 'strRoundName'.
A little more info would be helpful.

Bob
 
Hi

It is defined as a string in the expression:

Code:
Dim strRoundName as String

and then as the value of a textbox in the form in the expression:

Code:
strRoundName = Me.RoundName.Text

This works fine but I would like the variable 'strRoundName' to be used as the criteria for the DELETE statement.
 
Actually, I've just solved the problem. Here is the solution that worked if anyone else needs it:

Code:
Private Sub btnDelete_Click()

RoundName.SetFocus

Dim strRoundName As String
strRoundName = Me.RoundName.Text
Dim SQL As String

SQL = "DELETE Rounds.RoundName FROM Rounds WHERE (((Rounds.RoundName)= '" & strRoundName & "'));"
    
   DoCmd.RunSQL SQL
    
End Sub

As you can see, the string variable strRoundName needed the & for concatenation and double quotes for a string as well as the single quotes.

:)
 

Users who are viewing this thread

Back
Top Bottom