SQL Insert question

de ware

New Member
Joined
Feb 16, 2010
Messages
49
Hi,

Trying to insert data in an Database using SQL in VBA.
Let's assume i have two tables:

Books -> columns: description / pages / author
Author -> columns: Author_ID / Author

When inserting a new book the table books (using an xls workbook as interface) the user has a listbox where the possible Authorss are loaded.
So i have the 'Author' as a variable but I need to insert the Author_ID in the table books
How this is don in SQL language?

I guess the solution might be something like using 'INNER JOIN' which works for making selections but I cant't find how.
 

Some videos you may like

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Larry Haydn

Board Regular
Joined
Jul 18, 2019
Messages
94
Office Version
  1. 365
Platform
  1. Windows
Something like this?

INSERT INTO BOOK (Description, Pages, Author) VALUES ('" & CellA & "','" & CellB & "'," & (SELECT AuthorID FROM AUTHOR WHERE AuthorName='" & CellC & "');
 

Watch MrExcel Video

Forum statistics

Threads
1,122,319
Messages
5,595,465
Members
413,992
Latest member
CSEGUIN1973

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
Top