Copy and paste a record in same table - Access/VBA
Solved/Closed
PNyiam
Posts
21
Registration date
Tuesday July 17, 2018
Status
Member
Last seen
September 5, 2018
-
Aug 14, 2018 at 10:09 AM
PNyiam Posts 21 Registration date Tuesday July 17, 2018 Status Member Last seen September 5, 2018 - Aug 29, 2018 at 09:43 AM
PNyiam Posts 21 Registration date Tuesday July 17, 2018 Status Member Last seen September 5, 2018 - Aug 29, 2018 at 09:43 AM
Related:
- Ms access copy record to same table
- Ms access download - Download - Databases
- Messenger voice record downloader - Guide
- How to access google usa - Guide
- How to send voice record in messenger - Guide
- Access and downloading - Facebook Forum
Aug 15, 2018 at 03:49 AM
I am still very new to access, please can you explain in a bit more detail what you are suggesting?
Cheers
Updated on Aug 15, 2018 at 04:16 PM
Ok, there is an event called LOAD. Look at posted image:
Then after you select FOrm, in the second drop down, select LOAD.
As in:
After you press load, a new sub will appear called "form_load()". This will be one of the first things the form will do any time it loads. So, when it loads, you prepopulate the textbox with your predetermined values. As in:
The above script will set the two textbox to 0. This is an example of preloading values. There is other ways(through cache and such, but this is the easiest least complex method of doing so)!
Start with displaying a message first, and closing and opeing the form, to see what VBA thinks is loading and closing. Just because something is not visible, does not mean it has been CLOSED. So, make certain your method of LOAD is correct. Look at the drop down, those are all of the different events that can be triggered on!
Keep up the work, before you know your relationships will look as clustered as this:
LOL Have FUN!
Aug 23, 2018 at 06:24 AM
Thanks for the response...I couldn't use form load because I'm using the subform (image below), but I did go with the idea to take the the existing fields and load them into variables, with the plan to create a new record with these variables. Unfortunately I am getting a syntax error on my INSERT coding and was wondering if you can think what is wrong with it? I have tested all of the variables and the values are as required.
Dim DateRecorded As Date
Dim RaisedBy As String
Dim Facility As String
Dim Machine As String
Dim Frequency As String
Dim Period As Integer
Dim Description As String
DateRecorded = Date
RaisedBy = Forms.FrmCompletePM.SubCompletePM.Form.[Raised By]
Facility = Forms.FrmCompletePM.SubCompletePM.Form.[Facility]
Machine = Forms.FrmCompletePM.SubCompletePM.Form.[Machine]
Frequency = Forms.FrmCompletePM.SubCompletePM.Form.[Frequency]
Period = Forms.FrmCompletePM.SubCompletePM.Form.[Period]
Description = Forms.FrmCompletePM.SubCompletePM.Form.[Description]
DoCmd.RunSQL "INSERT INTO PlannedMaintenance(DateRecorded, RaisedBy, Facility, Machine, Frequency, Period, Description)"
Updated on Aug 23, 2018 at 05:02 PM
A properly syntaxed SQL statement is in the following format:
INSERT INTO TABLE_NAME (column1, column2, column3,...columnN) VALUES (value1, value2, value3,...valueN). SO in your case, you need (notice the quote structure):
"INSERT INTO PlannedMaintenance (column1, column2, column3,...columnN) " & _
"VALUES (" & DateRecorded & ", " & _
RaisedBy & ", " & _
Facility & ", " & _
Machine & ", " & _
Frequency & ", " & _
Period & ", " &_
Description & ");"
Or....
Of course, you have to treat each column as its data type. So in other words, text needs to have quotes around them, which can be tricky as you have to get the statement to print out the quotes, and not escape them. Format the SQL Statement first , then we will start looking at structure of the data types if you run into issues. Move forward.
Now the SQL script has the variables in place! Run a variable like this:
Now it will dislpay the statemtn so that you can troubleshoot the first couple of entries. After you are confident in what the query produces, REM out the MSGBOX!
I hope you are learning!
Have fun!
Aug 24, 2018 at 06:01 AM
So, I have implemented the changes discussed above...it seems to be reacting well to a lot of the fields, however there are a couple things...
First, the output for Facility and Machine, which are drawn from related tables (facilityList and assetList) are only showing the IDs.
Second, the Description field is causing an error...Not sure if this is because the table field type is Long Text. I'm assuming I don't have to declare an insert for any fields I want to be blank?
Couple images attached to help...
Thanks