Automatically create a new record when pressing button

behedwin

Active Member
Joined
Dec 10, 2014
Messages
399
Hello

Id like to create a button that automatically create a new row in a table, table is named ITLog_Table
The table contain the following columns.
ITLog_ID = primary key for the table
ITLogDatum = date field
Reason = picklist of 4 alternatives
ITComment = text field
IT_ID_SK = secondary key, relationship from IT_ID from a table called IT_Table


When i press the button i want following to happen
1. Create new row in table ITLog_Table so that ITLog_ID gets a new number.
2. ITLogDatum should be filled out with todays date
3. Reason should be filled out with the word "Inventerad"
4. ITComment should be left blank
5. IT_ID_SK should take the value from a textfield in the form where the button is located. Textfield is named txtIT_ID


Anyone able to help me with the code for this button?


I am using access 2016.
 
Last edited:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Maybe something like

Code:
Private Sub MyButton_Click()
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("ITLog_Table")
rs.AddNew
rs!ITLogDatum = Date
rs!Reason = "Inventerad"
rs!IT_ID_SK = Me.TxtIT_ID
rs.Update
rs.Close
Set rs = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,746
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top