Save button inserts unbound controls into append query

helmerr

New Member
Joined
Mar 14, 2014
Messages
8
I'm new to using append queries.

I found this page MS Access Unbound Forms and VBA which talks about creating a continuous form unbound from the original recordset. I think this is part of what I need.

I have a continuous form with the source being "qry_BLT_Update". This is an append query based off the table "tblBlotter".
On the form, I have several unbound textboxes, comboboxes and an option group. I simply want to be able to insert the values someone entered into the unbound controls to write to "tblBlotter" using a save button "btnSave". Then refresh/requery the source of the form to verify the new addition into the table.

I have the following code based on the page above, but not sure how it works.
Code:
Public Sub getRecords()
'Code for updating append query
'turn off warnings, delete then populate the local access table with the SQL data
 DoCmd.SetWarnings False

 DoCmd.RunSQL "DELETE FROM tblBlotter"
 DoCmd.OpenQuery "qry_BLT_Update", acViewNormal

 DoCmd.SetWarnings True

'dynamically set the recordsource and controlsource to the Access table.
 Me.RecordSource = "SELECT * FROM tblBlotter"
 txtMe.ID.ControlSource = "ID"
 txtEntryDate.ControlSource = "EntryDate"
 txtEntryTime.ControlSource = "EntryTime"
 cboBadgeNum.ControlSource = "BadgeNum"
 cboLocation.ControlSource = "Location"
 txtResponse.ControlSource = "Response"
 opOType.ControlSource.Value = "OType"

End Sub

It says to add the below code to the form load, but I'm unsure this is actually what I want. I'm also unsure that these codes are complete.
Code:
Private Sub Form_Load()
'Code for updating append query
 'Run Public Sub "getRecords()"
 getRecords
End Sub
Thanks in advance!
 

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.
Nevermind - was doing it all wrong. Just wanted to write to table.

Code:
Dim DB As Database
Dim rec As Recordset

Set DB = CurrentDb
Set rec = DB.OpenRecordset("Select * from tblBlotter")

rec.AddNew
rec("EntryDate") = Me.txtEntryDate
rec("EntryTime") = Me.txtEntryTime
rec("BadgeNum") = Me.cboBadge.Value
rec("Location") = Me.cboLocation.Value
rec("Response") = Me.txtResponse
rec("OType") = Me.opOType.Value

rec.Update
 
Upvote 0

Forum statistics

Threads
1,212,933
Messages
6,110,756
Members
448,295
Latest member
Uzair Tahir Khan

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