Kamis, 19 April 2018

Re: [MS_AccessPros] Cannot delete a record in a subform

 

What I would do is insert the SQL from a delete query. You record should have an Auto ID number. Assign that number to an integer (or long integer) variable (iID). Then use that variable as the filter criteria in the delete query so it only deletes that specific record. If the Delete Record button is on your main for & not your subform, make sure the variable is GLOBAL...


If you've never inserted a SQL query into VBA before, all you have to do is create a query deleting a record from your table with the Auto ID of 1 (or 123 or 456—doesn't matter), then caopy the SQL code of that query into the VBA in quotes and substituting the ID number with yiur vatiable, à la:

DoCmd.RunSQL _
    "DELETE FROM Customers " & _
    "WHERE ID = " & iID & ";"

After deleting the record requery your subform so it disappears.

Also, I always save the raw SQL code disabled in my VBA in case I want to throw it back into a regular query for easy adjustments, debugging or cannibalization:

'DELETE FROM Customers 
'WHERE ID = 123;

Let me know if you have any questions.

Frank

Sent from Yahoo Mail for iPhone

On Thursday, April 19, 2018, 9:19 PM, Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

 

Do the records allow edits?


From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of dbalorenzini@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Thursday, April 19, 2018 4:55:16 PM
To: MS_Access_Professionals@yahoogroups.com
Subject: [MS_AccessPros] Cannot delete a record in a subform
 


I can't seem to delete a record in a subform. I have subform which is a continuous form called sfrmDocumentList. On it i have a command button that is used to delete the record that it is on. Here is the code:

Private Sub cmdDeleteIndex_Click()

If MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo, "Delete Current Record ?") = vbYes Then

        If Me.NewRecord Then

            DoCmd.RunCommand acCmdUndo

          Else

            DoCmd.SetWarnings False

            DoCmd.RunCommand acCmdSelectRecord

            DoCmd.RunCommand acCmdDeleteRecord

            DoCmd.SetWarnings True

        End If

    End If

End Sub


Error: The command or action 'DeleteRecord' isn't avialble now.

I am not sure why it is not working.
Any ideas would be great.

Thank you,

Art Lorenzini
Sioux Falls, SD




__._,_.___

Posted by: Frank Sellers <sellers.frank@yahoo.co.uk>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (3)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.


.

__,_._,___

Tidak ada komentar:

Posting Komentar