By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,222 Members | 1,610 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,222 IT Pros & Developers. It's quick & easy.

Delete Records from a Form

100+
P: 145
Split off from To search record.
No worries :)

Let us know how this works for you.
It works well..Another question is I want to delete records from a form when I try to delete from the form, the records do not delete in the table. Why do this happen? I use the access button wizards.

The form name is [Delete Record]. The control are

textbox: [txtISBN],
button: cmdDelete,

where user enter the ISBN/ISSN number and click delete, the records will be deleted.
Oct 10 '08 #1
Share this Question
Share on Google+
8 Replies


100+
P: 145
I used this code
Expand|Select|Wrap|Line Numbers
  1. Dim strMsg As String
  2.     Dim strSQL As String
  3.  
  4.     strMsg = "Are you sure you want to delete this record? You cannot undo a deletion."
  5.  
  6.     If MsgBox(strMsg, vbYesNo) = vbYes Then
  7.         strSQL = "DELETE * FROM [Printing Media Library] WHERE [Printing Media Library].[ISBN/ISSN]= " & [Forms]![View/Delete Record]![txtISBN] & ";"
  8.     CurrentDb.Execute strSQL, dbFailOnError
  9.     DoCmd.GoToRecord , , acNewRec
  10. Else
  11.     DoCmd.OpenForm "Delete Record"
  12. End If
and there is error saying "data type mismatch in criteria expression"
Oct 10 '08 #2

100+
P: 145
and I want to know how to disable the design,view,layout view,so that user cannot change it....
Oct 10 '08 #3

NeoPa
Expert Mod 15k+
P: 31,707
and I want to know how to disable the design,view,layout view,so that user cannot change it....
Are you talking about the Form property Allow Design Changes? This should be set to Design View Only.
Oct 10 '08 #4

NeoPa
Expert Mod 15k+
P: 31,707
I used this code
Expand|Select|Wrap|Line Numbers
  1. Dim strMsg As String
  2.     Dim strSQL As String
  3.  
  4.     strMsg = "Are you sure you want to delete this record? You cannot undo a deletion."
  5.  
  6.     If MsgBox(strMsg, vbYesNo) = vbYes Then
  7.         strSQL = "DELETE * FROM [Printing Media Library] WHERE [Printing Media Library].[ISBN/ISSN]= " & [Forms]![View/Delete Record]![txtISBN] & ";"
  8.     CurrentDb.Execute strSQL, dbFailOnError
  9.     DoCmd.GoToRecord , , acNewRec
  10. Else
  11.     DoCmd.OpenForm "Delete Record"
  12. End If
and there is error saying "data type mismatch in criteria expression"
I expect [ISBN/ISSN] is a string/text field. In which case the format of your SQL is wrong. Try this for line #7 instead :
Expand|Select|Wrap|Line Numbers
  1. strSQL = "DELETE * " & _
  2.          "FROM [Printing Media Library] " & _
  3.          "WHERE [ISBN/ISSN]='" & [Forms]![View/Delete Record]![txtISBN] & "'"
Oct 10 '08 #5

100+
P: 145
I expect [ISBN/ISSN] is a string/text field. In which case the format of your SQL is wrong. Try this for line #7 instead :
Expand|Select|Wrap|Line Numbers
  1. strSQL = "DELETE * " & _
  2.          "FROM [Printing Media Library] " & _
  3.          "WHERE [ISBN/ISSN]='" & [Forms]![View/Delete Record]![txtISBN] & "'"
Thank you, it works now...thanks a lot
Oct 11 '08 #6

NeoPa
Expert Mod 15k+
P: 31,707
Excellent. That's two threads sorted in a week (or so) :D

Sounds like progress ;)
Oct 11 '08 #7

100+
P: 145
How can I make the report do not show any empty records? For example, in this [Company] table do not has address...I want the report only shows company that has address
Oct 19 '08 #8

NeoPa
Expert Mod 15k+
P: 31,707
OK. But do me a favour.

Post this question in it's own thread with all the required details (searching through the previous thread to remind myself of everything leaves me dooing all the work here. That's not the right balance).

Feel free to post a link in here to your new thread and I will certainly have a look and help. This should be a simple question, but without the facts to hand, it is far more complicated than it needs to be.
Oct 19 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.