Library code snippets

DataControl Example

A simple example of using the DataControl to browse a database

Comments

  1. 26 Apr 2007 at 09:01


    Private Sub txtAutoEno_KeyPress(KeyAscii As Integer)
       
        Dim eno As String
        Dim Srchflag As Boolean
        Srchflag = False 'Initially Search is not found
       
        'assigning Srch value
        eno = txtAutoEno.Text
       
        'If enter is pressed by user than auto-generate record
        If KeyAscii = 13 Then
       
            'Prompt if invalid search key is entered by user
            If Not IsNumeric(eno) Then
                MsgBox "Invalid Search Key Entered", vbCritical, "Search Error"
                clearAndFocus
                Exit Sub
            End If
           
            rs.Close
            rs.Open "Select * from emp where empid = " & eno, cn, adOpenDynamic, adLockOptimistic
       
            If rs.EOF <> True Then
                    Call display 'If Search is found
                    Srchflag = True
                    clearAndFocus
                    Exit Sub
            End If
       
            If Srchflag = False Then 'Display msg when search not found
                MsgBox "Search Not Found", vbInformation, "Search Result"
                clearAndFocus
            End If
           
        End If
    End Sub


    'Clear TextBox and SetFocus on it for fast and efficient result
    Private Sub clearAndFocus()
            txtAutoEno.Text = ""
            txtAutoEno.SetFocus
    End Sub


    'Supporting Function
    'Displaying Data into textbox from record source
    Private Sub display()
       txtEno.Text = Str(rs(0)) & " " 'Space is appended to avoid error when value is null
       txtEName.Text = rs(1) & " "
       txtESal.Text = Str(rs(2)) & " "
       txtEstatus.Text = rs(3) & " " 'as salary is numeric it is converted to string
       txtEDoj.Text = Str(rs(4)) & " "
       txtEDeptNo.Text = Str(rs(5)) & " "
    End Sub

    'Supporting Function
    'Simple clearing of textBox
    Private Sub clear()
       txtEno.Text = ""
       txtEName.Text = ""
       txtESal.Text = ""
       txtEstatus.Text = ""
       txtEDeptNo.Text = ""
    End Sub

    'Supporting Function
    'Assigning value of textbox to record source
    Private Sub assign()
       rs(0) = Val(txtEno.Text) 'val function will Convert text to numerice
       rs(1) = txtEName.Text
       rs(2) = Val(txtESal.Text)
       rs(3) = txtEstatus.Text
       rs(4) = txtEDoj.Text
       rs(5) = Val(txtEDeptNo.Text)
    End Sub





















































































  2. 11 Mar 2004 at 12:50

    Basically am trying to search a database by getting an input from the users selection on a list.
    the list contains names of countries and when i click that search button, how can i get the result of the search, say like i click paris and in the database, the flight to paris has 8 more available seats and the date, how can i show this information, by using a datagrid? if so how can i link, i know there are alot of "how's" in there but i would be realy and trually greatful if u can spare a minute.


    Cheers

  3. 01 Jan 1999 at 00:00

    This thread is for discussions of DataControl Example.

Leave a comment

Sign in or Join us (it's free).