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

validation

$
0
0
I just want to know how to code a validation for example a user wants to add/update a record but it has the same department for example in the database it has a department A but then the user wants to add another department with the same name how can I tell the user that the department exists?
code for ADD
Code:

If cmdadd.Caption = "Add" Then
    cmdedit.Enabled = False
    cmddelete.Enabled = False
    cbdep.Enabled = True
    txtcode.Enabled = True
    txtname.Enabled = True
    cmdadd.Caption = "Save"
    cmdclose.Caption = "Cancel"

ElseIf cmdadd.Caption = "Save" Then
        If txtcode.Text = "" Or txtname.Text = "" Or cbdep.Text = "" Then
            MsgBox "Please fill up the fields", vbInformation, "Case study!"
        Else
            OpenCon
            Set rs = New ADODB.Recordset
            rs.Open "Select * from [tblposition]", con, adOpenStatic, adLockOptimistic
            rs.AddNew
            rs![positioncode] = txtcode.Text
            rs![positionname] = txtname.Text
            rs![deptcode] = cbdep.Text
            rs.Update
            rs.Close
            con.Close
            Form1.Hide
            MsgBox "Record saved!", vbInformation, "Case study!"
            txtcode.Text = ""
            txtname.Text = ""
            cbdep.Text = ""
            cmdadd.Caption = "Add"
            cmdclose.Caption = "Close"
            Call Form_Load
        End If
End If

code for update
Code:

If cmdedit.Caption = "Edit" Then
    txtcode.Enabled = True
    txtname.Enabled = True
    cbdep.Enabled = True
    cmdadd.Enabled = False
    cbdep.Enabled = True
    cmddelete.Enabled = True
    cmdedit.Caption = "Update"
    cmdclose.Caption = "Cancel"
   
ElseIf cmdedit.Caption = "Update" Then
        If txtname.Text = "" Or txtcode.Text = "" Or cbdep.Text = "" Then
            MsgBox "Please fill up the fields!", vbInformation, "Case study"
        Else
            OpenCon
            Set rs = New ADODB.Recordset
            rs.Open "SELECT * FROM [tblposition]", con, adOpenStatic, adLockOptimistic
            rs![positioncode] = txtcode.Text
            rs![positionname] = txtname.Text
            rs![deptcode] = cbdep.Text
            rs.Update
            rs.Close
            con.Close
            ListView1.ListItems.Clear
            MsgBox "Record updated!", vbInformation, "Case study"
            Call Form_Load
            cmdedit.Caption = "Edit"
        End If
    End If
End Sub


Viewing all articles
Browse latest Browse all 21843

Trending Articles



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