VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This program will task the following: Update, Add, Find, Save using ODBC and ADODC but you will not

by Victor Cajarito "RedLAND" (1 Submission)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 4th September 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This program will task the following: Update, Add, Find, Save using ODBC and ADODC but you will not use any controls, this program will teach

API Declarations


'Programmer : Victor F. Cajarito
'Company/School : STI College Caloocan, Philippines
'Position : Programmer/DBA/Network Specialist/WEB Master
'Email : [email protected],[email protected]
'CellPhone : :)
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset


Rate This program will task the following: Update, Add, Find, Save using ODBC and ADODC but you will not



Dim sw As Boolean
If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Then
    MsgBox "All fields must be complete"
    Text4.SetFocus
Else
    sw = False
    rs.MoveFirst
    Do While Not rs.EOF
            If Text4.Text = rs!Acctnum Then
            sw = True
            End If
            rs.MoveNext
    Loop
    If sw = False Then
    cn.Execute "INSERT INTO NameTable VALUES ('" & Trim(Text1.Text) & "','" & Trim(Text2.Text) & "','" & Trim(Text3.Text) & "', '" & Trim(Text4.Text) & "')"
    MsgBox "Record successfully save!!!"
    Walana
    Else
    MsgBox "Record exist"
    Text4.SetFocus
    SendKeys "{HOME}+{end}"
    End If
End If
End Sub

Private Sub Command2_Click()
cn.Execute "UPDATE NameTable Set " & _
       " Fname = '" & Text1.Text & "' ," & _
       " Lname='" & Text2.Text & "', " & _
       " Age ='" & Text3.Text & "'" & _
       " where Acctnum='" & Text4.Text & "'"
MsgBox "Record successfully updated..."
Walana
End Sub

Private Sub Command4_Click() 'Add
merona
Text4.SetFocus
Command1.Enabled = True
Command2.Enabled = False
End Sub

Private Sub Command5_Click() 'Cancel
Walana
Command1.Enabled = False
Command2.Enabled = False
End Sub

Private Sub Command6_Click() 'Find
Dim strng As String
Dim sw As Boolean
rs.Close
cn.Close
cn.Open "DSN=VFCData"
rs.Open "SELECT * from NameTable", cn, adOpenStatic, adLockOptimistic
    strng = InputBox("Enter Account Number", Search)
    rs.Find "Acctnum='" & strng & "'"
    merona
    'No code for looping
    Text4.Text = rs!Acctnum
    Text1.Text = rs!Fname
    Text2.Text = rs!Lname
    Text3.Text = rs!Age
    MsgBox "Record found!", vbInformation, "Search Result"
    Text4.Enabled = False
    Text1.SetFocus
    Command2.Enabled = True
    
End Sub

Private Sub Form_Load() 'Form Load
    Walana
    cn.Open "DSN=VFCData"
    rs.Open "SELECT * from NameTable", cn, adOpenStatic, adLockOptimistic
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If MsgBox("Are you sure you want to exit", vbInformation + vbYesNo, "Close") = vbYes Then
   Unload Me
Else
  Cancel = True 'or 1
End If
End Sub
Sub Walana() 'Disabled Buttons
Text4.BackColor = &H80000004
Text3.BackColor = &H80000004
Text2.BackColor = &H80000004
Text1.BackColor = &H80000004

Text4.Enabled = False
Text3.Enabled = False
Text2.Enabled = False
Text1.Enabled = False

Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub

Sub merona() 'Enabled Buttons
Text4.BackColor = &H80000005
Text3.BackColor = &H80000005
Text2.BackColor = &H80000005
Text1.BackColor = &H80000005

Text4.Enabled = True
Text3.Enabled = True
Text2.Enabled = True
Text1.Enabled = True

Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub


Download this snippet    Add to My Saved Code

This program will task the following: Update, Add, Find, Save using ODBC and ADODC but you will not Comments

No comments have been posted about This program will task the following: Update, Add, Find, Save using ODBC and ADODC but you will not. Why not be the first to post a comment about This program will task the following: Update, Add, Find, Save using ODBC and ADODC but you will not.

Post your comment

Subject:
Message:
0/1000 characters