If only 1 record then cannot delete

Rusty

Registered User.
Local time
Today, 14:52
Joined
Apr 15, 2004
Messages
207
Hi guys,

I have a subform which contains data on different people working on the projects detailed in the main form.

The subform has a command button which deletes a person from a project. (just a delete function basically). But if there is only one person on the project I do not want this delete function to work.

I have tried working out the code along the lines of the stuff below but am unsure how to put the VBA equivalent of “if there is only 1 record, then”

Any help would be greatly appreciated.

Cheers,

Rusty
:D

Code:
Private Sub cmdDeleteSelectedRecord_Click()

‘if there is only 1 record, then

Cancel = True
Else
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
End If

End Sub
 
Can you dcount() the data to see if only one exists then do whatever?
 
is this any use?

not sure of the syntax,
but cant you use recordcount?

i.e.

if myform.recordset.recordcount < 1 then
"do something"

hth

John
 
Try this...
Code:
If Me.RecordsetClone.RecordCount <= 1 Then
'If DCount("*", "YourTable") <= 1 Then 'or try this line
    MsgBox "You can not delete the current record.", vbCritical, "Delete Error"
Else
    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdDeleteRecord
End If
 
Last edited:
If Recordset.Clone.RecordCount<=1 Then
'DoNothing
Else
DoCmd RunCommand etc

replace the do menu items, they're obsolete
 
ghudson said:
Try this...
Code:
If Me.RecordsetClone.RecordCount <= 1 Then

Bang on my good man, that worked a treat!!

Rusty
biggrinbounce2.gif
 

Users who are viewing this thread

Back
Top Bottom