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!

Save Button 1

Status
Not open for further replies.

AndreB

Programmer
Aug 21, 2001
13
US
I need a button that saves the contents of 2 ComboBoxes on a new Table and everytime this Button is pressed a new line on the Table is created with new contents saved...

andre
 

Here is one method to accomplish what you want. Place code like the following in the Click event of the button.

Sub cmdInsert_Click()

Dim sSQL As String
sSQL = "Insert Into Table1 (col1, col2) Values ('"
sSQL = sSQL & me.combobox1 & "','"
sSQL = sSQL & me.combobox2 & "')"
DoCmd.SetWarnings False
DoCmd.RunSQL sSQL
DoCmd.SetWarnings True
End Sub

NOTES:

Replace Table1, col1, col2 with the name of your table and columns.

Replace combobox1 and combobox2 with the names of your combo boxes. Terry L. Broadbent
Life would be easier if I had the source code. -Anonymous
 
The Code you sent me was very usefull.. thanx.
But now I have a new problem. I created a new column on my table to show Time/Date. So I need you to tell me how do I save Time/Date everytime the button is pressed???

andre
 

Use the Now() function. I assume col3 is the datetime column in the following example.

Sub cmdInsert_Click()

Dim sSQL As String
sSQL = "Insert Into Table1 "
sSQL = sSQL & "(col1, col2, col3) Values ('"
sSQL = sSQL & me.combobox1 & "','"
sSQL = sSQL & me.combobox2 & "',"
sSQL = sSQL & Now() & ")"
DoCmd.SetWarnings False
DoCmd.RunSQL sSQL
DoCmd.SetWarnings True
End Sub
Terry L. Broadbent
Life would be easier if I had the source code. -Anonymous
 
One last question: I need to compare the value selected in the ComboBox with the ones saved on the table. If the value is already on the table, a number 1 one is added by its side(on a new row), if not, the value is saved....
I don't know how to compare values in a ComboBox with the ones saved on a Table...

andre
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top