command button to delete tables

M

mike

Hi all,

I have two tables, user and user information. I want to
create a command button that takes parameter from a text
box and deletes the tables base on the parameter. Is it
possible?? How do you do this??

Thanks for the help...

Mike
 
G

Gary Miller

Mike,

Are you sure that you really want to delete your tables or
do you really want to delete certain records in them? Take a
look at Delete queries in Help and then get back with any
specific questions and details. They can reference a field
on a form for a criteria.

Gary Miller
Sisters, OR
 
M

mike

I mean deleting certain records within the tables where I
click on the command button and it deletes the records
along with its related entities base on the parameter I
entered in a text box.

Thanks for the help...

mike
 
G

Gary Miller

Thats what I thought. If you post your table names,
relationships, textbox name, fields involved, parameter data
type, etc... I am sure we can help you. Having a hard time
looking over your shoulder from here <gr>.

Gary Miller
Sisters, OR
 
M

mike

In the user table:

UserID (Primary Key) and it is an autonumber
UserName

In the User Information Table:

UserInfoID
Address
City
State
UserID (number with relationship from the user table,1 to
many)

i created a text box and a command button in a form. When
I enter user name in the text box and click the command
button. The command button will take the parameter from
the text box and delete the records and all of it entities
base on the paramter in the text box.

thanks for the help...

mike
 
G

Gary Miller

This is a much better detail level, but I am still cloudy on
what you are deleting. Is it that you want to delete a User
and then delete all of the user info from the UserInfo table
and any other child tables?

If this is the case, this would naturally happen by itself
if you turned on Referential Integrity with the Cascade
Delete option. Then if you delete a parent (User) record you
would get prompted that you will also delete all related
child records. You will find these options in the Under
View/Relationships.

If this is not what you want to do, give me more info on
what you do want to do.

Gary Miller
 
M

mike

I have done all those steps already. But I jst want to
know if it is possible to create a command button ( calls
Delete) and the command button takes the parameter from a
text box( the text box name property is call DelUser) and
delete the records base on the parameter. For example:

Enter user name: mike

Delete

Once the delete button is clicked, the delete button will
take the name "mike" and delete its record and all records
related to mike. This includes the userID,name, and any
records in the userInfo tables.

Any suggestion on how to do it??

Thanks,

mike
 
G

Gary Miller

Mike,

Here is one method using a Delete query SQL statement. In
the OnClick event of the command button put the following.
If you have the Cascade Delete turned on it should prompt
you about also deleting the child records if you delete the
parent so we will just have to delete the record from the
parent table. You would be better off putting in the user ID
in case you had two Mike's, but here is how to do it for the
name. It is kind of hard to see but I am using single quote
then double quote, then double, single, double.

Dim strSQL as String

strSQL = "DELETE * FROM tblUser WHERE [UserName] = '" &
Me!DelUser & "'"

DoCmd.RunSQL strSQL

Gary Miller
 
M

mike

Thanks for the help. If I need further assistant, I'll
create a new article. This article is getting very long.

Once again, thanks for your help.

Mike
-----Original Message-----
Mike,

Here is one method using a Delete query SQL statement. In
the OnClick event of the command button put the following.
If you have the Cascade Delete turned on it should prompt
you about also deleting the child records if you delete the
parent so we will just have to delete the record from the
parent table. You would be better off putting in the user ID
in case you had two Mike's, but here is how to do it for the
name. It is kind of hard to see but I am using single quote
then double quote, then double, single, double.

Dim strSQL as String

strSQL = "DELETE * FROM tblUser WHERE [UserName] = '" &
Me!DelUser & "'"

DoCmd.RunSQL strSQL

Gary Miller

mike said:
I have done all those steps already. But I jst want to
know if it is possible to create a command button ( calls
Delete) and the command button takes the parameter from a
text box( the text box name property is call DelUser) and
delete the records base on the parameter. For example:

Enter user name: mike

Delete

Once the delete button is clicked, the delete button will
take the name "mike" and delete its record and all records
related to mike. This includes the userID,name, and any
records in the userInfo tables.

Any suggestion on how to do it??

Thanks,

mike
cloudy
on record
you table,1
to
reference
a wrote
in from
a parameter.
Is


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top