473,386 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Copy a selected row from a subform to a new table

Hello all,

This is my first post/question on here, hope I can make myself clear :)

My employer wants me to build a storage management system which shows him his current supply of parts.

What I am trying to do is this:
I have a datasheet-subform on a normal form.
This subform shows data from a table (named searchtable).
The mainform has some controls to filter the data in the subform, all of that works.
Now I would like to click one of the visible records in the subform and copy that specific record to a new table (FetchTable) by pressing a button.

The searchtable contains the following columns:
Barcode | Description | Supply | Location
-------------------------------------------
text | text | double | text

The barcode column contains a unique key for each item.

I have read the solutions of doing this while using a textbox containing the key and a query with a WHERE clause.
Is there a way to click on a row and copy the selected row?
Mar 3 '14 #1
2 4542
Figured it out.

Expand|Select|Wrap|Line Numbers
  1.     Dim db As DAO.Database
  2.     Dim rs As DAO.Recordset
  3.     Set db = CurrentDb
  4.     Set rs = db.OpenRecordset("FetchTable", dbOpenDynaset)
  5.  
  6.     rs.AddNew
  7.     rs!Aantal = Forms!MainForm.FetchAantalBox.Value
  8.     rs!Omschrijving = Forms!MainForm!SearchTableControl!Omschrijving
  9.     rs!Locatie = Forms!MainForm!SearchTableControl!Locatie
  10.     rs.Update
  11.  
  12.     rs.Close
  13.     db.Close
  14.     Set rs = Nothing
  15.     Set db = Nothing
  16.  
Mar 3 '14 #2
ADezii
8,834 Expert 8TB
  1. I prefer a different approach that does not require you to:
    1. Create a Command Button on the Form.
    2. Select a Record in the Sub-Form.
    3. Click on the Command Button to execute the Copy Operation.
  2. My approach:
    1. Places Code in the DblClick() Event of the Primaty Key on the Sub-Form [Barcode].
    2. Once the [Barcode] Field is Dbl-Clicked, and it is not a New Record, will prompt the User to see if they wish to Copy the Record associated with that [Barcode] to FetchTable.
    3. If the User clicks Yes, performs the Copy Operation.
  3. This is simply just another approach, so I'll Post the Code for your Review:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Barcode_DblClick(Cancel As Integer)
  2. Dim intResponse As Integer
  3. Dim strSQL As String
  4.  
  5. With Me
  6.   strSQL = "INSERT INTO FetchTable ([Barcode],[Description],[Supply],[Location]) " & _
  7.            "VALUES('" & ![Barcode] & "','" & ![Description] & "'," & ![Supply] & "," & _
  8.            "'" & ![Location] & "')"
  9.  
  10.   If Not .NewRecord Then
  11.     intResponse = MsgBox("Copy Record with BarCode: [" & ![Barcode] & "] to FetchTable?", _
  12.                           vbQuestion + vbYesNo + vbDefaultButton1, "Copy Confirmation")
  13.       CurrentDb.Execute strSQL, dbFailOnError
  14.   End If
  15. End With
  16. End Sub
  17.  
Mar 3 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Bill | last post by:
I have a table I'd like to copy so I can edit it and play around with the data. How do I create copy of a table in SQl Server? Thanks, Bill
1
by: Steve | last post by:
ive been too busy trying to get my database and forms to work to really concern myself with backing things up or protecting the data in case a user really botches something up. is there anything...
0
by: dev121 | last post by:
Hi, I am currently trying to copy a single selected item from a listbox control in vba (excel). So far I have got this code, which doesn't work. <code> Private Sub btnAddNewOrder_Click()
1
by: romeodionisio | last post by:
How to copy data in table in a different SQL Server?.... Can anyone help me?.. Thanks....
8
by: blakerrr | last post by:
Hi All, Is it possible to create a carbon-copy of a table using VBA? I have a table called 'Junction' that stores the structure of a machines assemblies and subassemblies, and I need to create a...
2
by: bcarson86 | last post by:
Hi, I am trying to append a list of part numbers which is generated in a seperate table into a subform table which is on a main form. My main problem with getting it to work is that I need the part...
8
by: ALTAFAD | last post by:
How to copy selected (s) textfield, which those selected through checkbox I like to copy in clipboard. Access textfield data when front of the textfield checkbox is checked if not checked it...
4
by: Ploepsie | last post by:
Hey, first of all I want to state that I am very new to using Access and therefor the question might be relevantly easy to solve but I have spent hours thus far to find the answer online and in...
0
by: dekk | last post by:
Overview - Subform called 'Time' - Subform fields are named: Well Ref - this is the well reference Start Time - self explanatory End Time - self explanatory Activity - combo box selection...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.