Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21237

How to insert and Update 2 tables at once Via Sql

$
0
0
i created form that sells treatments and the history to save it
now a customer comes along and buys 12 treatments for 120 Euro
each time he comes to the salon to do a treatment that he paid for
i reduce 1 of the 12 that he buy.
when i enter for the first time a new cust with new treatment the i see it in the history aslo
when i go back to the same cust and update 1 treatment
then in the history it creates the same thing as this is a new customer and not updating correct.
i am a little lost here
this is my code
Code:

    If NewRec Then
        Dim NewID As Long
        NewID = NextID("ID", "Subscribers")
strSQL = "INSERT INTO Subscribers "
strSQL = strSQL & "(ID, SubEmpName, SubDate, SubCust, SubTreatment, SubQuantity, SubSold, SubRemain, SubPaymentMethod, SubPrice, SubTashlomim, SubTotal) "
strSQL = strSQL & "VALUES("
strSQL = strSQL & NewID & ","
strSQL = strSQL & "'" & RplS(CmbName.Text) & "',"
strSQL = strSQL & "#" & MyDate(DTstart.Value) & "#,"
strSQL = strSQL & "'" & RplS(TxtDesc.Text) & "',"
strSQL = strSQL & "'" & RplS(CmbTreat.Text) & "',"
strSQL = strSQL & CCur(Txt(0).Text) & ","
strSQL = strSQL & "0,"
strSQL = strSQL & CCur(Txt(0).Text) & "," 
strSQL = strSQL & "'" & RplS(CmbPayMethod.Text) & "',"
strSQL = strSQL & CCur(Txt(1).Text) & ","
strSQL = strSQL & CCur(CmbTashlomim.Text) & ","
strSQL = strSQL & CCur(Txt(2).Text) & ""
strSQL = strSQL & ")"
CN.Execute strSQL

Code:

  With FrmSubscribe.LsVw.SelectedItem
        strSQL = "UPDATE Subscribers SET "
strSQL = strSQL & "SubDate = #" & MyDate(DTstart.Value) & "#"
CN.Execute strSQL
strSQL = "Update Subscribers set SubSold = SubSold + " & RplS(txtPick & ",")
strSQL = strSQL & " SubRemain = SubRemain - " & RplS(txtPick.Text)
strSQL = strSQL & " where ID = " & .Tag
CN.Execute strSQL
        End With
    End If

Code:

            NewID = NextID("ID", "SubHistory")
    strSQL = "INSERT INTO SubHistory "
    strSQL = strSQL & "(ID,SubHistName,SubHistDate,SubHistCust,SubHistTreatment,SubHistQuantity,SubHistSold,SubHistRemain,SubHistPaymentMethod,SubHistPrice,SubHistTashLomim,SubHistTotal)"
    strSQL = strSQL & "VALUES("
strSQL = strSQL & NewID & ","
strSQL = strSQL & "'" & RplS(CmbName.Text) & "',"
strSQL = strSQL & "#" & MyDate(DTstart.Value) & "#,"
strSQL = strSQL & "'" & RplS(TxtDesc.Text) & "',"
strSQL = strSQL & "'" & RplS(CmbTreat.Text) & "',"
strSQL = strSQL & CCur(Txt(0).Text) & ","
strSQL = strSQL & "0,"
strSQL = strSQL & CCur(Txt(0).Text) & ","
'strSQL = strSQL & "'" & RplS(txtPick.text) & "',"
'strSQL = strSQL & "'" & RplS(TxtWorked.text & "',")
'strSQL = strSQL & "0,"
'strSQL = strSQL & "'" & RplS(TxtRemain.text) & "',"
strSQL = strSQL & "'" & RplS(CmbPayMethod.Text) & "',"
strSQL = strSQL & CCur(Txt(1).Text) & ","
strSQL = strSQL & RplS(CmbTashlomim.Text) & ","
strSQL = strSQL & CCur(Txt(2).Text) & ""
strSQL = strSQL & ")"
 CN.Execute strSQL


''            strSQL = "UPDATE SubHistory SET "
''strSQL = strSQL & "SubDate = #" & MyDate(DTstart.Value) & "#"
''CN.Execute strSQL
strSQL = "Update SubHistory set SubHistSold = SubHistSold + " & RplS(txtPick & ",")
strSQL = strSQL & " SubHistRemain = SubHistRemain - " & RplS(txtPick.Text)
strSQL = strSQL & " where ID = " & .Tag' error invaild qualified some thing like that
CN.Execute strSQL

any help i appriciate
salsa31

Viewing all articles
Browse latest Browse all 21237

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>