Hi All,
I have two tables: tblLicensedPrem and tblLicensedPrem History (these tables are identical).
tblLicensedPrem contains records for licensed premises. Over time details of a licensed premises change: e.g. the premises changes its company name, opening hours, manager, telephone number etc
What I would like to do is add a button to a form that when clicked:
- Firstly, appends the CURRENT record, in its current state, into the table tblLicensedPrem History
- Secondly, allows editing of the current record so details can be updated (although I am not to worried about this step at the moment).
I think I am best off doing this in VBA – however I am new to this and struggling.
As a test (I’m trying to take this on one stage at a time!) I have added a button named cmdArchiveData to my form and as a starter tried to copy only the record with PremID equal to 1, and only the first three fields in tblLicensedPrem . This event is running off of the OnClick Event of the form button. However for some reason this is not working.
Can anyone tell me where I am going wrong?
Regards,
Kevin
-----CODE---
Private Sub cmdArchiveData_ Click()
'Run Archive - Append to tblLicensedPrem History
Dim db As Database
Dim strSQLAp As String
Set db = CurrentDb
strSQLAp = "INSERT INTO tblLicensedPrem History( Prem_ID, LicNumber, PremName ) "
strSQLAp = strSQLAp & "SELECT tblLicensedPrem .Prem_ID, "
strSQLAp = strSQLAp & "tblLicensedPre m.LicNumber, "
strSQLAp = strSQLAp & "tblLicensedPre m.PremName, "
strSQLAp = strSQLAp & "FROM tblLicensedPrem "
strSQLAp = strSQLAp & "WHERE tblLicensedPrem .Prem_ID = 1;"
db.Execute strSQLAp
End Sub
3 2902 JustJim 407
Recognized Expert Contributor
Hi All,
I have two tables: tblLicensedPrem and tblLicensedPrem History (these tables are identical).
tblLicensedPrem contains records for licensed premises. Over time details of a licensed premises change: e.g. the premises changes its company name, opening hours, manager, telephone number etc
What I would like to do is add a button to a form that when clicked:
- Firstly, appends the CURRENT record, in its current state, into the table tblLicensedPrem History
- Secondly, allows editing of the current record so details can be updated (although I am not to worried about this step at the moment).
I think I am best off doing this in VBA – however I am new to this and struggling.
As a test (I’m trying to take this on one stage at a time!) I have added a button named cmdArchiveData to my form and as a starter tried to copy only the record with PremID equal to 1, and only the first three fields in tblLicensedPrem . This event is running off of the OnClick Event of the form button. However for some reason this is not working.
Can anyone tell me where I am going wrong?
Regards,
Kevin
-----CODE---
Private Sub cmdArchiveData_ Click()
'Run Archive - Append to tblLicensedPrem History
Dim db As Database
Dim strSQLAp As String
Set db = CurrentDb
strSQLAp = "INSERT INTO tblLicensedPrem History( Prem_ID, LicNumber, PremName ) "
strSQLAp = strSQLAp & "SELECT tblLicensedPrem .Prem_ID, "
strSQLAp = strSQLAp & "tblLicensedPre m.LicNumber, "
strSQLAp = strSQLAp & "tblLicensedPre m.PremName, "
strSQLAp = strSQLAp & "FROM tblLicensedPrem "
strSQLAp = strSQLAp & "WHERE tblLicensedPrem .Prem_ID = 1;"
db.Execute strSQLAp
End Sub
Hi,
Instead of working directly into the history table, try opening a recordset based on that table and appending your record to that recordset. Key words to check in the helpfiles would be recordset, addnewand of course, don't forget to update.
Jim
Hi Jim,
But wouldn't it be easier to just run one append query? I will actually want to append all fields from the original table into the history table and it seems a single append query should work for this - or am I incorrent?
I am getting the following error at present when I run my code give above:
Run-time error '3134':
Syntax error in INSERT INTO statment.
When I go into debug the arrow points to the line ---> db.Execute strSQLAp
Regards,
Kevin
JustJim 407
Recognized Expert Contributor
Hi Jim,
But wouldn't it be easier to just run one append query? I will actually want to append all fields from the original table into the history table and it seems a single append query should work for this - or am I incorrent?
I am getting the following error at present when I run my code give above:
Run-time error '3134':
Syntax error in INSERT INTO statment.
When I go into debug the arrow points to the line ---> db.Execute strSQLAp
Regards,
Kevin
OK, I thought you wanted to do it one at a time as you moved through the records on your form.
The INSERT INTO clause may have problems with the spaces and brackets in the first line of the SQL block and doesn't need the semi-colon at the end.
Here is a way to do the duplicate checking and insertion in one go using VBA. Of course declarations need to be made, field names changed to suit you and the WHERE clause changed as well. - ' Find unmatched Programme entries in table "tblNewArrivals"/"Tbl_Programmes" and open that data as a recordset
-
strSQL = "SELECT tblNewArrivals.School, tblNewArrivals.Campus " & _
-
"FROM tblNewArrivals LEFT JOIN Tbl_Programmes ON tblNewArrivals.School = Tbl_Programmes.School_No " & _
-
"WHERE (((Tbl_Programmes.School_No) Is Null) AND ((Tbl_Programmes.Campus_No) Is Null));"
-
Set rsNewProg = dbNAP.OpenRecordset(strSQL)
-
-
' also open the real programmes table as a recordset
-
strSQL = "SELECT * from Tbl_Programmes"
-
Set rsProg = dbNAP.OpenRecordset(strSQL)
-
-
' Add records from new programmes to real programmes table
-
Do Until rsNewProg.EOF
-
-
With rsProg
-
.AddNew
-
!School_No = rsNewProg!School
-
!Campus_No = rsNewProg!Campus
-
!NAP_Provider_ID = 9 ' no information in tblNewArrivals for these fields, but they are required in the
-
!Outpost_Host_ID = 9 ' table to fulfill Referential Integrity requirements. ID #9 is a "No Provider" entry
-
.Update
-
End With
-
-
rsNewProg.MoveNext
-
-
Loop
Enjoy
Jim
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Tony |
last post by:
Hello,
I am having difficulty in getting the current record of the current
form to show after pressing a command button that takes me to another
form. The command button takes me to another form that I want to show
the record of the previous form I left.
The problem is that the form does not show any other record but the
current one from the previous form. I want it to open to that current
record and it does however I can only view...
|
by: Paul Wagstaff |
last post by:
Hi there
I have 2 tables: tblAccuracy & tblClearance
Users add new records to tblAccuracy using frmRegister. Under specific
conditions I need to append the current record from frmRegister into
tblClearance. I was thinking of placing the code on the form's BeforeUpdate
event so that it will fire whether the user closes the form or attempts to
create another record.
|
by: DBQueen |
last post by:
I have a subform which is in Continuous Forms view.
I have added a button to the bottom of the page to move to the next record
using the button wizard (result: DoCmd.GoToRecord , , acNext).
I want all of the controls in whatever is the CURRENT record to have it's
data bolded on the screen. (Question #1: Is there a SIMPLE way to refer to
the Current Record?)
I've been trying to use a Bookmark to specify the current record, but it
|
by: Richard Coutts |
last post by:
I have a Continuous Form where each record has a button that activates
another form that simplifies entering values into the record. The
activated form has the equivalent of a "Done" button. I'd like to
write an OnClick event that populates the contents of the current
record of the parent form with the values entered in the popup form.
So, the activated form needs to set the values of the current record
of the parent form. How do you...
|
by: Ray Holtz |
last post by:
I have a form that shows a single record based on a query criteria.
When I click a button it is set to use an append query to copy that
record to a separate table, then deletes the record from the first
table. Both tables have a 'DateTime' field that shows when it was last
updated using the Now function.
What I am trying to do is get the 'DateTime' field updated after the
append query copies it to the new table. I have tried updating...
| |
by: kabradley |
last post by:
Hello Everyone,
So, thanks to nico's help I was finally able to 'finish' our companies access database. For the past week or so though,I have been designing forms that contain a subform and an option group so that whenever a certain button on the option group is pressed the correct subform source object property is changed to display the correct form. For instance, if they click "add new investment" the subform's source object is now changed to...
|
by: easydoesit |
last post by:
Hello all,
I am looking for a way to be able to enter data into fields on a form, then be able to e-mail a report that shows only that record.
This is what I have thus far:
At the end of my Form, I have a Command Button. Right now the Command Button has an On Click... to basically E-mail a Report.
Here is my Visual Basic code for it:
|
by: SJ1000 |
last post by:
Hi,
I think I have a simple question that I just can't figure out. I want to have a command button on a form (via a macro) run a query to append the data on that form to another table.I want it to append the current record on the open form. I am not familiar with VBE so I want to use a macro.
How does the query pull the current record? I have an ID field and have tried setting the focus on that field but it still pulls all the records not...
|
by: hikosj |
last post by:
Hi all,
I have a problem with a query in access that I cant seem to figure out. I have a form named frmRecruitment with a subform named sfrmParticipant. At the moment I am using an append query to append records from 'sfrmParticipant' to 'frmIntervention' using a button on a main form 'frmRecruitment'.
This append query appends all the records from
'sfrmParticipant' to 'frmIntervention' but I only want to append the record that is...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |