Thanks Steve. Now what I have is a form for taking all types of payments
involved in self storage . These payments are posted to 2 tables (Ledger &
Payments). Now a tenant can pay other charges as you can see below that are
not always rent. Only when rent is paid are the PaidFrom and PaidThru fields
have dates other wise they will be blank or Null.
Now I've done it with If then statements as you can see below in the SQL
statement. I did try Me.txtPaidThru = Null and got an error "Improper use of
Null". I also tried to leave the text box blank and got a syntax error due
to the ## in the SQL statement for a date. I tried the Nz() function but it
puts a time in the field even though it is marked as a short date. I've got
it working now by simply using a set of if then statements in the SQL string
to stop these fields for being appended, hence they are left Null.
'Append Payment to the LEDGER
strSQL = "INSERT INTO LEDGER ( Transaction, LedgerID, "
strSQL = strSQL & "PaymentDate, PaymentAmount, "
' here I stop the 4 fields that are part of the rent
If PayRent = 1 Then 'The PayRent is Public var. that is
either 1 to pay rent or 0 no rent.
strSQL = strSQL & "RentRate, PaidFrom, PaidThru, Rent, "
End If
strSQL = strSQL & "AdmistrationFee, Lock, LateFees, NSFCheckFee, "
strSQL = strSQL & "LockCutFee, AuctionFee, MiscChg, MiscChgDesc, Waved,
"
strSQL = strSQL & "WaveDesc, RentAllowance, RentAllReason,
CreditApplied, "
strSQL = strSQL & "CreditEarned, CreditReason, PreviousBalDue,
BalanceDue)"
strSQL = strSQL & " SELECT "
strSQL = strSQL & Me.txtTrans & " AS Transaction, '"
strSQL = strSQL & Me.txtLedgerID & "' AS LedgerID, #"
strSQL = strSQL & Date & "# As PaymentDate, "
strSQL = strSQL & [fsubTakePayment].Form![txtTotalPaid] & " AS
PaymentAmount, "
' here I limit the fields unless paying rent
If PayRent = 1 Then
strSQL = strSQL & Me.Rate & " AS RentRate, "
strSQL = strSQL & "#" & Me.NewPaidFrom & "# AS PaidFrom, "
strSQL = strSQL & "#" & Me.txtPaidThru & "# AS PaidThru, "
strSQL = strSQL & Me.TotalRentPaid & " AS Rent, "
End If
strSQL = strSQL & Me.AdmFee & " AS AdmistrationFee, "
strSQL = strSQL & Me.PurLock & " AS Lock, "
strSQL = strSQL & Me.LateFeesPaid & " AS LateFees, "
strSQL = strSQL & Me.PayNSFFee & " AS NSFCheckFee, "
strSQL = strSQL & Me.LockCutPaid & " AS LockCutFee, "
strSQL = strSQL & Me.AuctionPaid & " AS AuctionFee, "
strSQL = strSQL & Me.MiscChgs & " AS MiscChg, "
strSQL = strSQL & Nz(Me.CboMiscChg, 0) & " AS MiscChgDesc, "
strSQL = strSQL & Me.FeesWaved & " AS Waved, "
strSQL = strSQL & Nz(Me.cboWaveDesc, 0) & " AS WaveDesc, "
strSQL = strSQL & Me.RENTALLOWENCE & " AS RentAllowance, "
strSQL = strSQL & Nz(Me.CboRentAllow, 0) & " AS RentAllReason, "
strSQL = strSQL & Nz(Me.CreditsApp, 0) & " AS CreditApplied, "
strSQL = strSQL & tmpCreditEarned & " AS CreditEarned, "
strSQL = strSQL & tmpCreditReason & " AS CreditReason, "
strSQL = strSQL & Me.PrevBal & " AS PreviousBalDue, "
strSQL = strSQL & Me.txtBalanceDue & " AS BalanceDue ;"