Copy records from table1 to table2 based on inputbox value

yschuerm

New Member
Joined
Jun 18, 2015
Messages
14
Hi,

I want to be able to copy a selection of table1 to table2 where a specific field in table1 equals value of inputbox.

I have got the following code, but get an error on [Competitors].MoveFirst

Tables are "Competitors" and "Result Search"

Code:
Private Sub cmdBernArt_Click()

Dim Message As String
Dim tab1 As Recordset
Dim db As Database
Set db = CurrentDb
Dim sql As String
Message = InputBox("Enter BernerArticle")

sql = "INSERT INTO [Result Search] * " & _
              "SELECT * " & _
              "FROM [Competitors] " & _
              "WHERE [Competitors].[BernerArtNr] = '" & Message & "';"

[Competitors].MoveFirst

Do While Not [Competitors].EOF


DoCmd.RunSQL sql
[Competitors].MoveNext

Loop

End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
no code is needed for this.
It is a single append query. you are reinventing the wheel.
Take your sql shown, put it in a query, and append to the table.
 
Upvote 0
You may have a reason for using code when you don't have to, so my comment is, I don't believe you can use the first wildcard. Try
sql = "INSERT INTO [Result Search] SELECT * FROM [Competitors] "
sql = sql & "WHERE [Competitors].[BernerArtNr] = '" & Message & "';"
I have too much trouble with line continuation characters, so I don't use them.
 
Upvote 0

Forum statistics

Threads
1,221,849
Messages
6,162,425
Members
451,765
Latest member
craigvan888

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