query values and destination fields error

B

Bob Vance

I am trying to get this code to add HorseID to tblDailyCharge.HorseID when I
update this form, but I am getting the error:
Number of query values and destination fields are not the same!

Private Sub subSetInvoiceDetailsValues()

CurrentProject.Connection.Execute "INSERT INTO
tblAdditionCharge(InvoiceID,ChargeID,HorseID,DayNo,ChargeNumber,AdditionCharge,
" _
& " AdditionChargeAmount)SELECT " & lngInvoiceID & "," & "ChargeID"
_
& "," & cbHorseName.value & ",DayNo,ChargeNumber,AdditionCharge, " _
& " AdditionChargeAmount FROM tmpAdditionCharge"

If IsNull(tbTotalDays1.value) = True Or tbTotalDays1.value = "" Then
Exit Sub
ElseIf IsNull(cbDailyCharge1.value) = True Or cbDailyCharge1.value = ""
Then
Exit Sub

'***TRY TO ADD HorseID HERE***
Else
CurrentProject.Connection.Execute "INSERT INTO
tblDailyCharge(InvoiceID,HorseID,StartDate,EndDate,TotalDays,DailyCharge, "
_
& " DailyChargeRate,DailyChargeAmount)Values(" & lngInvoiceID & ",'"
& Format(tbStartDate1.value, "dd/mm/yyyy") _
& "','" & Format(tbEndDate1.value, "dd/mm/yyyy") & "'," &
tbTotalDays1.value & ",'" & cbDailyCharge1.value _
& "'," & tbDailyChargeRate1.value & "," & tbDailyChargeAmount1.value
& ")"
End If
 
B

Bob Vance

Bob Vance said:
I am trying to get this code to add HorseID to tblDailyCharge.HorseID when
I update this form, but I am getting the error:
Number of query values and destination fields are not the same!

Private Sub subSetInvoiceDetailsValues()

CurrentProject.Connection.Execute "INSERT INTO
tblAdditionCharge(InvoiceID,ChargeID,HorseID,DayNo,ChargeNumber,AdditionCharge,
" _
& " AdditionChargeAmount)SELECT " & lngInvoiceID & "," & "ChargeID"
_
& "," & cbHorseName.value & ",DayNo,ChargeNumber,AdditionCharge, "
_
& " AdditionChargeAmount FROM tmpAdditionCharge"

If IsNull(tbTotalDays1.value) = True Or tbTotalDays1.value = "" Then
Exit Sub
ElseIf IsNull(cbDailyCharge1.value) = True Or cbDailyCharge1.value = ""
Then
Exit Sub

'***TRY TO ADD HorseID HERE***
Else
CurrentProject.Connection.Execute "INSERT INTO
tblDailyCharge(InvoiceID,HorseID,StartDate,EndDate,TotalDays,DailyCharge,
" _
& " DailyChargeRate,DailyChargeAmount)Values(" & lngInvoiceID &
",'" & Format(tbStartDate1.value, "dd/mm/yyyy") _
& "','" & Format(tbEndDate1.value, "dd/mm/yyyy") & "'," &
tbTotalDays1.value & ",'" & cbDailyCharge1.value _
& "'," & tbDailyChargeRate1.value & "," &
tbDailyChargeAmount1.value & ")"
End If
OOPS HorseId is first column of cbHorseName
.Fields("HorseID") = cbHorseName.value
 
B

Bob Vance

THANKS,DONE IT :)

Private Sub subSetInvoiceDetailsValues()

CurrentProject.Connection.Execute "INSERT INTO
tblAdditionCharge(InvoiceID,ChargeID,HorseID,DayNo,ChargeNumber,AdditionCharge,
" _
& " AdditionChargeAmount)SELECT " & lngInvoiceID & "," & "ChargeID"
_
& "," & cbHorseName.value & ",DayNo,ChargeNumber,AdditionCharge, " _
& " AdditionChargeAmount FROM tmpAdditionCharge"

If IsNull(tbTotalDays1.value) = True Or tbTotalDays1.value = "" Then
Exit Sub
ElseIf IsNull(cbDailyCharge1.value) = True Or cbDailyCharge1.value = ""
Then
Exit Sub
Else
CurrentProject.Connection.Execute "INSERT INTO
tblDailyCharge(InvoiceID,StartDate,EndDate,TotalDays,DailyCharge, " _
& " DailyChargeRate,DailyChargeAmount, HorseID)Values(" &
lngInvoiceID & ",'" & Format(tbStartDate1.value, "dd/mm/yyyy") _
& "','" & Format(tbEndDate1.value, "dd/mm/yyyy") & "'," &
tbTotalDays1.value & ",'" & cbDailyCharge1.value _
& "'," & tbDailyChargeRate1.value & "," & tbDailyChargeAmount1.value
& "," & cbHorseName.value & ")"
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Calculation Problem 1

Top