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

Move from a Table using a Form 1

Status
Not open for further replies.

AndreB

Programmer
Aug 21, 2001
13
US
I have a Form that saves the content(a number) of a ComboBox on a Table. If Option #1 is selected. My problem is how to delete this line from the first Table and save on a second Table, if option #2 is selected??

Note: In my program nothing can be saved on Table #2 if it is not on Table #1 first.

andre
 
I don't understand very well what you are asking. Are you asking how to delete a record from a table? There are several ways to do that. The simplest way in your case seems to be the Delete method of the Recordset that (I assume) you are already using the AddNew method with.

First, position the Recordset to the record you want to delete by using the Seek (dbOpenTable) or FindFirst (dbOpenDynaset) method. Then, use the Delete method of the Recordset to delete the record.
 
You have a little sequencing problem. If Option 2 is selected run an append query to add the value(s) to the second table. Then delete the value from the ComboBox.

If the ComboBox is bound to the table just blank the field when Option2 is selected:

Private Sub Option2_Click()
DoCmd.SetWarnings False
DoCmd.OpenQuery "AppendToTable2"
Me!ComboBox = Null
DoCmd.SetWarnings True
End Sub

If the ComboBox is not bound to the table then write a delete query to remove the record. In the query design grid pull down the asterisk for the table and then the value that corresponds to what is displayed in ComboBox. In the criteria line for the WHERE value put the name of the ComboBox, e.g. Forms!MyForm!ComboBox

Private Sub Option2_Click()
DoCmd.SetWarnings False
DoCmd.OpenQuery "AppendToTable2"
DoCmd.OpenQuery "DeleteFromTable1"
Me!ComboBox = Null
DoCmd.SetWarnings True
End Sub

Uncle Jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top