ps, Kevin, if the record you are deleting may have related records, you
need to decide how you will handle that ...
'~~~~~~~~~~~~~~~~~~~~~
with currentDb
.execute sSQL
if .recordcount <>1 then 'assuming criteria specifies primary key
msgbox "record couldn't be deleted -- maybe there are related
records that need to be deleted first?",,"Could NOT Delete"
'alternately, you could use code to delete them -- if that is
really what you want to do!
end if
end with 'CurrentDb
'~~~~~~~~~~~~~~~~~~~~~
also, if you are in code behind form, before attempting to delete, make
sure there are not unsaved changes first
'~~~~~~~~~~~~~~~~~~~~~
with me
if .dirty then .undo
if .newrecord then exit sub 'or function -- new record so just
don't save it
end with 'me
'~~~~~~~~~~~~~~~~~~~~~
~crystal
VBA code you can use in your projects
http://msaccessgurus.com/code.htm
On 1/31/2019 11:41 AM, crystal 8 strive4peace2008@yahoo.com
[MS_Access_Professionals] wrote:
> hi Kevin,
>
> I like using SQL to delete as opposed to DoCmd.DeleteRecord
>
> '~~~~~~~~~~~~~~~~~~~~~~~~~
> dim sSQL as string
> sSQL = "DELETE A.* FROM [MyTable] as A WHERE [MyPrimaryKey]=" &
> me.controlnamePK
> currentDb.execute sSQL
> '~~~~~~~~~~~~~~~~~~~~~~~~~
>
> to close form:
>
> '~~~~~~~~~~~~~~~~~~~~~~~~~
> DoCmd.Close acForm, me.name 'if in code behind form
> '~~~~~~~~~~~~~~~~~~~~~~~~~
>
> I generally also specify the Save parameter as No when closing the form.
> Make sure you save your code first.
>
> ~crystal
>
>
> On 1/31/2019 8:21 AM, Qingqing qingqinga@yahoo.com
> [MS_Access_Professionals] wrote:
>> Dear All,
>> How to delete a current record in an opened Single form and close the form after the deletion. Thanks. I have tried many ways, none of them work really well. Please help.
>> Best Regards,
>> Kevin
>>
>>
>> ------------------------------------
>> Posted by: Qingqing <qingqinga@yahoo.com>
>> ------------------------------------
>>
>>
>> ------------------------------------
>>
>> Yahoo Groups Links
>>
>>
>>
>
> ------------------------------------
> Posted by: crystal 8 <strive4peace2008@yahoo.com>
> ------------------------------------
>
>
> ------------------------------------
>
> Yahoo Groups Links
>
>
>
Posted by: crystal 8 <strive4peace2008@yahoo.com>
Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (3) |
Tidak ada komentar:
Posting Komentar