Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8015227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:11:47+00:00 2026-06-04T20:11:47+00:00

I am newbiew using VBA/FK/SQL server all in one. I am creating simple purchase

  • 0

I am newbiew using VBA/FK/SQL server all in one. I am creating simple purchase order workbook user interface in excel.

I have created two tables:

CREATE TABLE [dbo].[PurchaseOrder](
[PKPurchaseOrderID] [bigint] IDENTITY(1,1) NOT NULL,
[PurchaseOrderNumber] [bigint] NULL,
[PurchaseOrderDate] [date] NULL,
[PurchaseOrderTime] [int] NULL,
[PurchaseOrderSupplierID] [nvarchar](50) NULL,
[ShipToA1] [nvarchar](50) NULL,
[ShipToA2] [nvarchar](50) NULL,
[ShipToA3] [nvarchar](50) NULL,
[ShipToA4] [nvarchar](50) NULL,
 CONSTRAINT [PK_PurchaseOrder] PRIMARY KEY CLUSTERED 
(
    [PKPurchaseOrderID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF,     
ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

and

CREATE TABLE [dbo].[PurchaseOrderLines](
[PKPurchaseOrderLineID] [bigint] IDENTITY(1,1) NOT NULL,
[FKPurchaseOrderID] [bigint] NULL,
[Quantity] [smallint] NULL,
[Item] [nchar](25) NULL,
[Description] [nvarchar](50) NULL,
[siteID] [nchar](10) NULL,
[UnitPrice] [money] NULL,
[LineTotal] [money] NULL,

 CONSTRAINT [PK_PurchaseOrderLines] PRIMARY KEY CLUSTERED 

(

    [PKPurchaseOrderLineID] ASC

)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, 
ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

) ON [PRIMARY]



ALTER TABLE [dbo].[PurchaseOrderLines]  WITH CHECK ADD  CONSTRAINT 
[FK_PurchaseOrderLines_PurchaseOrder] FOREIGN KEY([FKPurchaseOrderID])

REFERENCES [dbo].[PurchaseOrder] ([PKPurchaseOrderID])


ALTER TABLE [dbo].[PurchaseOrderLines] CHECK CONSTRAINT 
[FK_PurchaseOrderLines_PurchaseOrder]

GO

I want to achieve that in the background when user clicks the button both tables are updated.

I am not sure how I can link brand new row created in the PurchaseOrder table with FK in the PurchaseorderLine table.

What i plan to do for single user interface:

  1. Insert New Order
  2. Use Max(PKPurchaseOrderID) as FK for new order lines table.

How can I determine currently inserted Order ID(PKPurchaseOrderID) if multiple users are working/submitting orders at the same time. I am afraid order lines may be assigned to different orders if I use my plan. e.g.

Please advise.

I use SQL Server 2008 and Excel 2007/2010

Many thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:11:49+00:00Added an answer on June 4, 2026 at 8:11 pm

    I would create a stored procedure that inserts the new row and returns the ID with SCOPE_IDENTITY()

    Here’s a decent article on the different “identity” methods in SQL Server.

    http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem using VBA to execute a SQL query and copy the
Newbie question since I'm not up to speed using maven at all. I'm trying
Newbie question here: I'm using ANSI C on server to crunch numbers for a
I'm a newbie using OpenMP with C++. I was doing a simple function, loading
A newbie question - I'm using [NSUserDefaults standardUserDefaults] to store user specified preferences. While
Newbie here. I'm trying to encrypt the user password using SHA-256 after they've made
newbie here. I successfully created a chat server using c# (server partial code below,
I am a newbie. Using class clsMRDateTime and am creating 2 instances of objects
I am a newbie using Python and Numpy. I thought this would be simple
I am (newbie) using Kohana V 3.0.3 and my directory structure is: pojectsys (kohana's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.