You are on page 1of 2

Dim c As New ADODB.

Connection
Dim r As New ADODB.Recordset
Dim img1 As String

Private Sub Combo1_Click()


'======================================================
r.Open "Select Name from tbl_states Where Country_Id = (Select Id from
tbl_countries where Name ='" & Combo1.Text & "')", c, adOpenKeyset,
adLockPessimistic
While Not r.EOF
ComboBox2.AddItem r.Fields(0)
r.MoveNext
Wend
r.Close
'======================================================
End Sub

Private Sub ComboBox2_Click()


'======================================================
r.Open "Select Name from tbl_cities Where State_Id = (Select Id from tbl_states
where Name ='" & ComboBox2.Text & "')", c, adOpenKeyset, adLockPessimistic
While Not r.EOF
ComboBox1.AddItem r.Fields(0)
r.MoveNext
Wend
r.Close
'======================================================
End Sub

Private Sub Command2_Click()


CommonDialog1.ShowOpen
img1 = CommonDialog1.FileName
Image1.Picture = LoadPicture(img1)
End Sub

Private Sub Command3_Click()


addarti.Visible = False
End Sub

Private Sub CommandButton1_Click()


Dim a As String
If (TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or img1 = "" Or
Combo1 = "" Or ComboBox1 = "" Or ComboBox2 = "") Then
MsgBox "Please fill all data field"
Else
Dim sql As String

sql = "Insert into tbl_artist


(Firstname,Middlename,Lastname,Place,State,Country,Image) values("
sql = sql & "'" & TextBox1.Text & "',"
sql = sql & "'" & TextBox2.Text & "',"
sql = sql & "'" & TextBox3.Text & "',"
sql = sql & "'" & ComboBox2.Text & "',"
sql = sql & "'" & ComboBox1.Text & "',"
sql = sql & "'" & Combo1.Text & "',"
sql = sql & "'" & img1 & "')"

c.Execute sql
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
Combo1 = ""
ComboBox1 = ""
ComboBox2 = ""
Image1 = Nothing
MsgBox "Record saved"
End If
End Sub

Private Sub CommandButton3_Click()

End Sub
Private Sub Form_Load()
c.Open _
"Provider=sqloledb;" & _
"Data Source=DESKTOP-2TQIM0J\SQLEXPRESS;" & _
"Initial Catalog=Arts;" & _
"Trusted_Connection=yes;"
'======================================================
r.Open "Select Name from tbl_countries", c, adOpenKeyset, adLockPessimistic
While Not r.EOF
Combo1.AddItem r.Fields(0)
r.MoveNext
Wend
r.Close
'======================================================
End Sub

Private Sub Form_Unload(Cancel As Integer)


c.Close
End Sub
'=====================================Validation===================================
====
Private Sub TextBox1_KeyPress(KeyAscii As MSForms.ReturnInteger)
Call Alph(KeyAscii)
End Sub
Private Sub TextBox2_KeyPress(KeyAscii As MSForms.ReturnInteger)
Call Alph(KeyAscii)
End Sub
Private Sub TextBox3_KeyPress(KeyAscii As MSForms.ReturnInteger)
Call Alph(KeyAscii)
End Sub
Private Sub ComboBox1_KeyPress(KeyAscii As MSForms.ReturnInteger)
Call Alph(KeyAscii)
End Sub
Private Sub ComboBox2_KeyPress(KeyAscii As MSForms.ReturnInteger)
Call Alph(KeyAscii)
End Sub
Private Sub ComboBox3_KeyPress(KeyAscii As MSForms.ReturnInteger)
Call Alph(KeyAscii)
End Sub

You might also like