VBA Delete Query Assistance

cstickman

Board Regular
Joined
Oct 23, 2008
Messages
137
Hey Guys,

I just need a simple assistance with a delete query. I have a table called tbluser and five columns, ID, racf, username, security, password. When the user selects on a name and then clicks on the delete button. I have this as my code, but I am getting an error for the table name. I believe it is a compile error. Below is my code and I am sure it is something that I am missing.

I do apologize in advance for asking what seems to be small questions, but I am trying to learn and understand it. Thanks

<code>
Dim strSQL As String

strSQL = "DELETE * FROM "tbluser" WHERE username = 'Me.txtusername';"

CurrentDb.Execute strSQL
</code>
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
The important thing to remember when creating strings is that anything between the double-quotes are considered "literal" text. If you want to return the values from variables or objects, they must be outside of the double-quotes, i.e.
Code:
[COLOR=#333333][FONT=monospace]strSQL = "DELETE * FROM tbluser WHERE username = '" & Me.txtusername & "';"[/FONT][/COLOR]

Like I recommend in the previous post we were working on, use a MsgBox to return the value of your string. This allows you to see what it is, and if you have written a valid command, i.e.
Code:
MsgBox strSQL

What I like to do is manually create a query that does an example of what I want to do, then switch to SQL View to see what it should look like. This is what you are trying to build in VBA. So you can use the MsgBox to compare what you have built with what it needs to look like.
 
Last edited:
Upvote 0
Thanks Joe!! I see what I was doing wrong. I will have to remember the & and spaces between the variables. I will start getting into habit of typing in MsgBox strSQL.
 
Upvote 0

Forum statistics

Threads
1,221,854
Messages
6,162,450
Members
451,765
Latest member
craigvan888

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top