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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems deleting a record in MS Access VBA

Status
Not open for further replies.

mdProgrammer

Programmer
Oct 2, 2004
71
US
I'm using the following code to delete a record:

Code:
Private Sub btnDeleteRecord_Click()
    EdtMsg = MsgBox("Are you sure you want to delete this record?", vbYesNo, "Delete Record")
    If EdtMsg = vbNo Then
        Exit Sub
    End If
    DoCmd.SetWarnings False
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
End Sub

The problem is... it isn't deleting it. I'm using a button on a form (without the record navigation controls enabled) to delete the current record.
 
Comment [green][tt]'DoCmd.SetWarnings False[/tt][/green] out of you procedure as see if Access gives you an error when you try to delete the record.

Hope this helps,
CMP

Funny thing about being unemployed, weekends don't mean quite so much, just means you get to hang out with your working friends. Primus
 
Nope, that didn't work.


Also, one more question while I'm at it. (I'm not as familar with VBA as say, VB.NET, or C/C++/C#)


I have an edit record form in which I want to display info from another table. The form's data is set to a query, in which I have a function to save the data. This form has a field that's the primary key (name field - which will always be unique). Now, I have a listbox that refers to another table that uses the name field as a foreign key.

(table 1: Name (Primary Key), other fields...)
(table 2: tableID (PK), Name (FK), SomeDescription)

I can get all of the records from table 2 into the listbox just fine, but the problem comes in when I try to make the query equal to the name field. (i.e., [Screen].[ActiveForm]![nameField]). It won't display anything.
 
On the first, we know it didn't work. Should I assume that Access did not throw and error when you turned off set warnings? Did you at least get the delete record confirmation?

On the second, make sure the the second field (name) is the bound column if you are trying to use the listbox.value as the filter value for the form.

Funny thing about being unemployed, weekends don't mean quite so much, just means you get to hang out with your working friends. Primus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top