VISUAL  BASIC                   

 

1.   About the action BUTTONS and CODE :

 

 

                        In previous class, you have created the BUTTONS and the name of each button has been given.

 

(a)    (a)    Button INSERT :  Double click on the button (design time) or from the menu click ‘View

Then click ‘Code’. A blank or some coded window will appear. If you directly double

Clicking on the button, the code window will appear like . . . . .

 

Private Sub Insert_Click()

 

End Sub

 

You have to write your code between these two lines as below : -

Private Sub cmd1_click()

Data1.Recordset.AddNew

t1.Text = " "                      ‘ t1, t2, t3, t4 . .t8  are TextBox Name.

t2.Text = " "

t3.Text = " "

t4.Text = " "

t5.Text = " "

t7.Text = " "

t8.Text = " "

End Sub

 

(b)    (b)    For SAVE button : -

       Private Sub cmd2_Click()

Data1.Recordset.Update

MsgBox "The Record is Updated now.", vbOKOnly

Data1.Recordset.MoveFirst

       End Sub

 

(c)    (c)    For MODIFY button : -

       Private Sub cmd3_Click()

MsgBox "Would You Like to Modify The Record ?", vbOKCancel

Data1.Recordset.Edit

        End Sub

 

(d)    (d)    For FIRST (<<) button : -

        Private Sub cmd03_Click()

Data1.Recordset.MoveFirst

  End Sub

 

(e)    (e)    For PREVIOUS (<) button : -

       Private Sub cmd04_Click()

               Data1.Recordset.MovePrevious

       End Sub

 

(f)      (f)      For NEXT (>) button : -

        Private Sub cmd05_Click()

            Data1.Recordset.MoveNext

        End Sub

 

(g)    (g)    For LAST (>>) button : -

       Private Sub cmd06_Click()

Data1.Recordset.MoveLast

       End Sub

 

(h)    (h)    For DELETE  button : -

        Private Sub cmd4_Click()

MsgBox "Really You want to Delete the Record ?", vbOKCancel

Data1.Recordset.Delete

Data1.Recordset.MoveNext

MsgBox "The Record has been deleted."

       End Sub

 

(I )   For REFRESH button : -

          Private Sub cmd5_Click()

  Data1.Recordset.MoveFirst

          End Sub

 

(i)      (i)      For CLOSE  button : -

         Private Sub cmd6_Click()

   MsgBox "Is Your Work Finished ?", vbOKCancel

   End   

         End Sub

 

(j)      (j)      For FIND button : -

        Private Sub cmdFnd_Click()

Dim fd1 As String

Dim fd2 As String

fd2 = t1.Text

fd1 = "select * from abc_trng where roll_no = " & fd2

Data1.RecordSource = fd1

Data1.Refresh

        End Sub

 

2.      2.      Set the ToolTipText  Property for every button if you like it.

 Click to Add a Record

 
 

 


For INSERT button :  ToolTipText :   

       And  so on. . . .

      While the form is running and mouse pointer over the button the text will display.

 

3.      3.      Click on menu ‘Project  then choose the last option from the menu (click) ‘Project Property’

On the next screen click  General  tab and set ‘Start Up Object’ as ‘Form1’ or the name of

The Form and click ‘OK’.

 

4.      4.      To Test the Form, Click ‘Run’ then clickStart’.  Your form will run and you check everything

On the form whether it is working satisfactorily or not. At last click ‘Close’ on your Form,

The form will be closed and again will reform as design mode.

 

5.      5.      Click on menu ‘Tools’ (from pull down menu on first line) then click ‘Menu Editor’

Set  Caption =  Data  ,  Name = sheet  Click ‘Next’ Click ‘Right arrow key’

Caption and Name will be blank now. Set  Caption = DataSheet  , Name = sheet1

Click ‘OK’. When returns to form-design  you can see a menu item is created on the upper

Left corner of the form.

 

6.      6.      Click on menu ‘Project’ then  Add Form’ Next screen select ‘Form’ and click ‘Open’.

Another blank form will be added with your project. Set name of this form frmSheet

Through property.

 

7.      7.      Click on ‘Data’ not on menu but on your own form then Double click on DataSheet

Code window  will appear. Write the code like. . . .

 

Private Sub frmSheet_Click()

    Dim fr  As New frmSheet

    fr .Show

End Sub

 

                                                Data Sheet  Form below

                       

 

8.      8.      Drag down a ‘Data Control’, a ‘Label’, a ‘TextBox’ and a  Button  on the top line of

The Screen. Through properties connect the table ‘abc_trng with Data1.

 

9.      9.      Click on menu ‘Project’  then click  ‘Component’ from the next screen select ‘Controls’ tab

       select check boxes Of  Microsoft Data Bound Grid Control 5.0 (SP3)’ and click ‘OK’.   

 

10.  10.  Now on ToolBar  you could find a new item named ‘DBGrid’ select and drag down this

Grid control on the form as shown on the above form.

 

11.  11.  Set DBGrid’s  properties as

Data1

 
 

 


 

Data Source :                                            

 

12.  12.  Below the DBGrid  create ‘Sort’, ‘Close’ ,  ‘Execute’ buttons and one ‘TextBox’ as on

The form above. Set the Property of TextBox . . .

True

 
 

 


 

                                    MultiLine :                               

 

                       

                        (a)  Code for ‘EXECUTE’ button   : -

Private Sub cmdExecute_Click()

Data1.RecordSource = Text1.Text

Data1.Refresh

End Sub

 

                        (b)  Code for ‘CLOSE’ button   : -

Private Sub cmdClose_Click()

Unload Me

End Sub

 

                        (c)  Code for ‘SORT’ button   : -

Private Sub cmdSort_Click()

Dim srt As String

srt = "select * from abc_trng order by name"

Data1.RecordSource = srt

Data1.Refresh

End Sub

 

                        (d)  Code for ‘CLICK’ button   : -

Private Sub cmdClick_Click()

Dim aa As String

Dim bb As String

aa = ts1.Text

bb = "select * from abc_trng where name = " & aa

Data1.RecordSource = bb

Data1.Refresh

End Sub

 

13.  13.  Save the project again. Click ‘Run’ then ‘Start’ or press ‘F5’ key.  Firstly your

Data Entry form will appear on the screen. On this form Click ‘Data’ on the

Upper left corner of the form then click DataSheet.

 

                                                      Back

 

 

 

 

 

 

 

 

Hosted by www.Geocities.ws

1