ACCESS DB help - using delete button on form and does not delete.

G

Guest

i have a simple table with one column and 30 unique records. i designated
the field as a primary key indexed no dupes because this is a pick list and i
need each text record to be unique.

on a simple form i have a combo box with that list as the control. under it
i have a delete button. i test by choosing record to delete in combo box and
then i get a message that i cannot change because it would create dupe in
table.
question - how do i delete a record from this table without that error? why
is that error showing when i am taking away - not adding?

thanks soooooooooooooooo much! this is actual db for work.
 
J

John Welch

You have to give us lots more info, like the code for your delete button or
we can't tell what's going on.
-John
 
G

Guest

hey john here is the delete button code...........
i think it is a property problem - i now have the first record deleted once
i hit the delte button regardless of which record i choose in the table.
weird! thanks a ton man.

Private Sub Command30_Click()
On Error GoTo Err_Command30_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Exit_Command30_Click:
Exit Sub

Err_Command30_Click:
MsgBox Err.Description
Resume Exit_Command30_Click

End Sub
 
G

Guest

any idea guys? really stuck on this easy one. i pick a record from a combo
box and hit the delete button and it sysematicall deletes the fisrst one in
record list.
thanks!
 
J

John Welch

I can't quite tell what your button is doing, because it's just calling menu
items 8 and 6, which are probably cut and paste things.
Did you write that code? It's better to have the code do what you want
directly rather than calling menu items.
Are you trying to delete items from the combobox or from a different table
based on what is chosen in the combobox?
I think the former. Here is how I would do that:
(I'm assuming you only choose one item at a time in the combo box and that
the items are text rather than numbers)
Private Sub Command30_Click()
On Error GoTo Err_Command30_Click
if not isnull(me.NameOfCombobox) then
docmd.runsql "Delete * from YourTableName where
YourTableName.YourFieldName = '" & me.NameOfComboBox & "'"
'(Note carefully the use of single and double quotes. If the items are
numbers then skip the single quotes)
me.NameOfComboBox.requery
end if
Exit_Command30_Click:
Exit Sub

Err_Command30_Click:
MsgBox Err.Description
Resume Exit_Command30_Click

End Sub

hope this helps
-John
 
G

Guest

john - you are a god send. i THINK the problem was when i added a combo box
- i was binding it to the wrong control. i think that i may do it your way
tho. if i can ever help you in any way i will. thanks man. time to go and
i will try your way tomorrow. i will update! peace!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top