Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete record in main form FROM SubForm

Status
Not open for further replies.

mauricionava

Programmer
Jul 8, 2005
209
0
0
US
Hello, I have a form that has a delete button which opens a subform with a text field to enter password and if password correct, then delete the record. But, it does not delete the record in the main form. It says that it deleted the record but it does not. Maybe it is deleting a record in the subform and not in the main form?

How do I set it up so it can delete the record in the form and record where I open my delete form from?

Thanks
 
The delete button opens the subform and grants the focus to the subform where you enter the password. Before you can expect it to delete the record on the main form, you need to set the focus back to the main form.

Otherwise you are deleting the password entry and indeed it did delete a record, only not the one on the main form.

-- Fast Learner, I Think

Here's something to think about. How come you never see a headline like 'Psychic Wins Lottery!'? - Jay Leno
 
and how do I set the focus to the main form when I open the password form?

Thanks for replying
 
First thread you mention opening a subform. If that is what you need the following sample code should work.

on main form Form_Load

Code:
me.sfmPassword.visible = false

on main form "Delete" command button
Code:
me.sfmPassword.vidible = true
me.sfmPassword.setfocus

on "OK" command button in subform which user will click on after entering password. "july" is sample password.
Code:
Private Sub cmdOK()
On Error GoTo error_cmd

If Me.txtPassword = "july" Then
    Me.Parent!cmdDel.SetFocus
    If Me.NewRecord Then
        DoCmd.RunCommand acCmdUndo
    Else
        DoCmd.RunCommand acCmdDeleteRecord
    End If
    Me.Parent!SubForm.Visible = False
    Exit Sub
Else
    MsgBox "Incorrect Password.", vbOKOnly
    Me.TxtPass.SetFocus
    DoCmd.CancelEvent
End If
Exit Sub

error_cmd:
If Err = 2046 Then
    MsgBox "no record selected"
Else
    MsgBox "Error " & Err & ": " & Error
End If

End Sub


-- Fast Learner, I Think

Here's something to think about. How come you never see a headline like 'Psychic Wins Lottery!'? - Jay Leno
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top