[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

MS Access Delete Query

Posted on 2006-05-31
15
Medium Priority
?
646 Views
Last Modified: 2012-05-05
I have a form that has a text box and a command button in MS Access and I'm having trouble with it.

Private Sub Delete_Record_Click()
On Error GoTo Err_Delete_Record_Click

    DoCmd.SetWarnings False ' remove the nasty prompts
    Dim strSQL As String
    strSQL = "DELETE vin_id FROM _vin_info WHERE (((vin_num)=[Enter Vin Number:]));"
    DoCmd.RunSQL strSQL

Exit_Delete_Record_Click:
    Exit Sub

Err_Delete_Record_Click:
    MsgBox Err.Description
    Resume Exit_Delete_Record_Click
   
End Sub

I want the DoCmd.RunSQL strSQL to prompt the user when the form loads only once and I also want the word "Deleted" to appear in the vin_num text area.

Thanks
0
Comment
Question by:rae_rae
  • 8
  • 3
  • 2
  • +2
15 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16805042
what about this:
    strSQL = "DELETE vin_id FROM _vin_info WHERE (((vin_num)=[Enter Vin Number to Delete:]));"
0
 
LVL 3

Author Comment

by:rae_rae
ID: 16805142
The prompt isn't really what I want to change though...at least, as far as the text within the prompt.
My code:
strSQL = "DELETE vin_id FROM _vin_info WHERE (((vin_num)=[Enter Vin Number:]));"
Your code:
strSQL = "DELETE vin_id FROM _vin_info WHERE (((vin_num)=[Enter Vin Number to Delete:]));"

What I'm wanting:
'I want the DoCmd.RunSQL strSQL to prompt the user when the form loads only once and I also want the word "Deleted" to appear in the vin_num text area.'

Thanks again!
0
 
LVL 3

Author Comment

by:rae_rae
ID: 16805146
Oh! I almost forgot, the word "Deleted" should appear in the text area on command button press: on Delete_Record_Click()
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16805148
well, sorry, then I don't understand that request really...
0
 
LVL 77

Expert Comment

by:peter57r
ID: 16805335
Hi rae_rae,

You cannot display deleted records  so what you are asking is not possible.


Pete
0
 
LVL 11

Expert Comment

by:pootle_flump
ID: 16805459
I don't get it either but:
DoCmd.SetWarnings False ' remove the nasty prompts

Does a *lot* more than remove nasty prompts. I recommend you use

CurrentDb.Execute strSQL

OR change your exit code:

Exit_Delete_Record_Click:
DoCmd.SetWarnings True ' prevents devastating errors
    Exit Sub


HTH
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 16806214
when you use a DELETE query, you do not delete a specific field, as:


"DELETE vin_id FROM _vin_info WHERE (((vin_num)=[Enter Vin Number:]));"


rather, you are deleteing an entire row, so the statement reads:

"DELETE * FROM _vin_info WHERE (((vin_num)=[Enter Vin Number:]));"

AW

0
 
LVL 3

Author Comment

by:rae_rae
ID: 16809639
Ok I have:
Private Sub Delete_Record_Click()
On Error GoTo Err_Delete_Record_Click

    DoCmd.SetWarnings False ' remove the nasty prompts
    Dim strSQL As String
    strSQL = "DELETE * FROM _vin_info WHERE (((vin_num)=[Enter Vin Number to Delete:]));"
    DoCmd.RunSQL strSQL

Exit_Delete_Record_Click:
DoCmd.SetWarnings True ' prevents devastating errors
    Exit Sub

Err_Delete_Record_Click:
    MsgBox Err.Description
    Resume Exit_Delete_Record_Click
   
End Sub

So, instead of (((vin_num)=[Enter Vin Number to Delete:]));" prompting the user, is it possible for the value in (((vin_num) text box to be used to specify which record to delete?

If I could do this, I think that would be the best route.

What I mean is this:
The form opens, the user can enter the record number to delete and then use the Delete_Record command button to delete the record instead of having to [Enter Vin Number to Delete:].

Thanks everybody!
0
 
LVL 3

Author Comment

by:rae_rae
ID: 16814008
Ok...

Let me attack this from a different approach since I don't seem to be understood...perhaps I'm just slow...

INSERT INTO _vin_info
VALUES ('', 'vin_num', 'box_num', 'date_ent=Date', 'date_exp=DateSerial(Year([date_ent]),Month([date_ent])+36,Day([date_ent]))');

It won't store the information that the user types in...:(

If you guys can tell me how to do this, the 140 points are yours.
Thanks
0
 
LVL 3

Author Comment

by:rae_rae
ID: 16814017
Btw, I'm not using a form any more since the form will not allow create, update or delete querys :(
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16814029
>The form opens, the user can enter the record number to delete and then use the Delete_Record command button to delete the record instead of having to [Enter Vin Number to Delete:].>

yes, put the name of the textbox that the user enter the number to:

Private Sub Delete_Record_Click()
On Error GoTo Err_Delete_Record_Click

    DoCmd.SetWarnings False ' remove the nasty prompts
    Dim strSQL As String
    strSQL = "DELETE * FROM _vin_info WHERE (((vin_num)=" & textbpxDeleteVIN.value
    DoCmd.RunSQL strSQL

Exit_Delete_Record_Click:
DoCmd.SetWarnings True ' prevents devastating errors
    Exit Sub

Err_Delete_Record_Click:
    MsgBox Err.Description
    Resume Exit_Delete_Record_Click
   
End Sub
0
 
LVL 3

Author Comment

by:rae_rae
ID: 16814064
Ok, I get an error on the delete query. "Object Required".
I have no idea what that is telling me or how to fix it.
Just so you know, the post I made @ Date: 06/01/2006 11:47PM PDT is an INSERT query.
The way I see it, If I can handle the INSERT I can probably pull off the delete query.

Take a look at:
Ok...

Let me attack this from a different approach since I don't seem to be understood...perhaps I'm just slow...

INSERT INTO _vin_info
VALUES ('', 'vin_num', 'box_num', 'date_ent=Date', 'date_exp=DateSerial(Year([date_ent]),Month([date_ent])+36,Day([date_ent]))');

It won't store the information that the user types in...:(

If you guys can tell me how to do this, the 140 points are yours.
Thanks

It is the post I'm speaking of.
Thanks again.
0
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 280 total points
ID: 16820323
please show us the layout of the table you have named _vin_info.

Also, what are the variables that hold the values that the user types in, that you want to save in the table?

AW
0
 
LVL 3

Author Comment

by:rae_rae
ID: 16823819
Table _vin_info: vin_id --> vin_num, box_num, date_ent, date_exp
Where vin_id functionally determines all other fields
and vin_num carries a 6 digit vin number and box_num carries a <= 4 digit box number
and date_ent carries date() or today's date
and date_exp carries DateSerial(Year([date_ent]),Month([date_ent])+36,Day([date_ent]))
which should allow me to query at a later date to see which vin numbers need to be purged from the system.

I wanted to use forms to let the user enter the data: vin_num and box_num having the date_ent and date_exp
automatically fill in for them but it seems that Access does not allow users to define forms that create update or delete items within a defined table. :(

Help is something I sorely need. lol
Thanks.
0
 
LVL 3

Author Comment

by:rae_rae
ID: 16824159
I have elected to just use the ms query windows instead of forms. I got it figured out.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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…
Suggested Courses

834 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