hw to add multiple conditions in a single update statement?? my project goes code like this...

If release.Enabled = True And nonosc.Enabled = True Then
        Dim rst12 As New Recordset
        Dim sql12 As String
        sql12 = "update Passport_Release_Information_N set Ename2='" & taker.Text & "' ,Any_ID1='" & takerid.Text & "' ,E_ID1 = '" & Label7.Caption & "',R_Status= '" & status.Caption & "' WHERE R_ID_N='ASDF'"
        CN.Execute sql12
        status.Caption = "RELEASED"
Else
    If release.Enabled = True And osc.Enabled = True Then
        Dim rst13 As New Recordset
        Dim sql13 As String
        sql13 = "update Passport_Release_Information_O set E_ID_3='" & takerid.Text & "' ,E_ID_4 = '" & Label31.Caption & "',R_Status= '" & status.Caption & "' WHERE R_ID_N='ASDF'"
        CN.Execute sql13
        status.Caption = "RELEASED"
    End If
End If

plz help!... thankx!...
take care!

Recommended Answers

All 8 Replies

Since in the Branching Statement one and only one condition is executed, u can first finish getting the query. and then apply the Execute Statement.

Dim sql12 As String
If release.Enabled = True And nonosc.Enabled = True Then
        sql12 = "update Passport_Release_Information_N set Ename2='" & taker.Text & "' ,Any_ID1='" & takerid.Text & "' ,E_ID1 = '" & Label7.Caption & "',R_Status= '" & status.Caption & "' WHERE R_ID_N='ASDF'"
Else
    If release.Enabled = True And osc.Enabled = True Then
        sql12 = "update Passport_Release_Information_O set E_ID_3='" & takerid.Text & "' ,E_ID_4 = '" & Label31.Caption & "',R_Status= '" & status.Caption & "' WHERE R_ID_N='ASDF'"
    Else
        sql12 = ""
    End If
End If
If sql12 <> "" then
  CN.Execute sql12
  status.Caption = "RELEASED"
End If

Regards
Shaik Akthar

Why would you put this code inside the else statement?

If release.Enabled = True And osc.Enabled = True Then
        Dim rst13 As New Recordset
        Dim sql13 As String
        sql13 = "update Passport_Release_Information_O set E_ID_3='" & takerid.Text & "' ,E_ID_4 = '" & Label31.Caption & "',R_Status= '" & status.Caption & "' WHERE R_ID_N='ASDF'"
        CN.Execute sql13
        status.Caption = "RELEASED"
    End If

You can just keep adding conditions in an if statement like so:

if something = 2 then
something
ElseIf something = 2 then
something
ElseIf something - 2 then
something

...and so on.

im didnt rele understand ur questions because the and in your code already gives multiple conditions.
so if i helped np ;)

hi. i assume nonosc and osc are only the condtions if Release.Enabled = True

Dim rst As New Recordset
Dim sql As String

If Release.Enabled = True Then
    If nonosc.Enabled = True Then
        sql = "update Passport_Release_Information_N set Ename2='" & taker.Text & "' ,Any_ID1='" & takerid.Text & "' ,E_ID1 = '" & Label7.Caption & "',R_Status= '" & Status.Caption & "' WHERE R_ID_N='ASDF'"
    Else
        sql = "update Passport_Release_Information_O set E_ID_3='" & takerid.Text & "' ,E_ID_4 = '" & Label31.Caption & "',R_Status= '" & Status.Caption & "' WHERE R_ID_N='ASDF'"
    End If
    CN.Execute sql
    Status.Caption = "RELEASED"
End If

hi. i assume nonosc and osc are only the condtions if

they are checkboxes... the command button is common for both the types... but the updation has to happen in different databases... so they r based on these conditions....

thnxk for all the responses!

Does your problem resolved by the replies?

Does your problem resolved by the replies?

no... its showing error when only one of the two checkboxes is selected... coz its still updating in the other database....

thanx 4 all responses!!

hi. check first if youre recordset is open then try closing it before opening it again. and for the checkboxes i think its its if check1.value = 1.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.