accessjack
Programmer
I have two tables: tblDeposits (App, Bank, Account) and tblMatrix (App, Bank, Account, Year, Amount)
The composite primary key in tblDeposits is App + Bank + Account. The composite primary key in tblMatrix is App + Bank + Account + Year.
I have a form where user chooses Year from a combo box (cboYear), then hits a button to add the composite primary key to the tblMatrix if it does not exist. My code is not working, am I missing parenthesis or is it something else? The multipe AND statements get me confused on both the JOIN and the WHERE clause.
sql = "INSERT INTO [tblMatrix]([App], [Bank], [Account], [Year]) " & _
"SELECT [tblDeposits].[App], [tblDeposits].[Bank], [tblDeposits].[Account], " & "'" & cboYear.Column(4) & "'" & _
"FROM [tblDeposits] " & _
"LEFT JOIN [tblMatrix] " & _
"ON [tblDeposits].[App] = [tblMatrix].[App] " & _
"AND [tblDeposits].[Bank] = [tblMatrix].[Bank] " & _
"AND [tblDeposits].[Account] = [tblMatrix].[Account] " & _
"WHERE [tblMatrix].App Is Null " & _
"AND [tblMatrix].Bank Is Null " & _
"AND [tblMatrix].Account Is Null " & _
"AND [tblMatrix].Year Is Null"
The composite primary key in tblDeposits is App + Bank + Account. The composite primary key in tblMatrix is App + Bank + Account + Year.
I have a form where user chooses Year from a combo box (cboYear), then hits a button to add the composite primary key to the tblMatrix if it does not exist. My code is not working, am I missing parenthesis or is it something else? The multipe AND statements get me confused on both the JOIN and the WHERE clause.
sql = "INSERT INTO [tblMatrix]([App], [Bank], [Account], [Year]) " & _
"SELECT [tblDeposits].[App], [tblDeposits].[Bank], [tblDeposits].[Account], " & "'" & cboYear.Column(4) & "'" & _
"FROM [tblDeposits] " & _
"LEFT JOIN [tblMatrix] " & _
"ON [tblDeposits].[App] = [tblMatrix].[App] " & _
"AND [tblDeposits].[Bank] = [tblMatrix].[Bank] " & _
"AND [tblDeposits].[Account] = [tblMatrix].[Account] " & _
"WHERE [tblMatrix].App Is Null " & _
"AND [tblMatrix].Bank Is Null " & _
"AND [tblMatrix].Account Is Null " & _
"AND [tblMatrix].Year Is Null"