Hi All,
I am inserting data in access database using Vb6. Data is getting inserted but when I try to fetch it again, it returns an empty row.I have an idea that I have to use update/refresh statement but not getting where to use it. Please help!!!
Below is the code :
Option Explicit
Private Sub SubmitCmd_Click()
Dim conn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As New ADODB.Recordset
Dim sConnString As String
Dim msg As Integer
Dim sSql As String
'Making Connection to DB
sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Tool\P_and_E\P_and_E.mdb"
conn.Open sConnString
Set cmd.ActiveConnection = conn
If IsNull(Me.EmpNoTxt) Or Me.EmpNoTxt = "" Then
MsgBox "Employee number cannot be empty!", vbOKOnly + vbExclamation, "Empty Field"
Me.EmpNoTxt.SetFocus
End If
sSql = "INSERT INTO Personal_Info VALUES ('" & EmpNoTxt.Text & "', " _
& "'" & NameTxt.Text & " ','" & LocCmb.Text & "','" & NidTxt.Text & "', " _
& "'" & PassprtTxt.Text & "','" & NidTxt.Text & "','" & DOBCal.Value & "', " _
& "'" & AetJD.Value & "','" & IDTxt.Text & "','" & ResTxt.Text & "', " _
& "'" & OffTxt.Text & "','" & MobTxt.Text & "','" & AddTxt.Text & "','Allocated')"
cmd.CommandText = sSql
cmd.CommandType = adCmdText
Set rs = cmd.Execute(sSql)
'Set cmd = Nothing
conn.Close
Set conn = Nothing
msg = MsgBox("The Details have been added successfully", 0, "Msg")
Unload Me
End Sub