Tuesday, December 11, 2007

How to delete the Record during runtime

How to delete the Record during runtime

To delete the Record during runtime

Step 1:

Click the Delete Button if you want to delete a record from the database:

Step 2:

Click the Refresh Button. The current record will be deleted from the database.


How to insert the New Record during runtime

How to insert the New Record during runtime

To insert the New Record during runtime

Step 1:

You can run the program now. Click the ADD Button to add a new record to the database:

Step 2:

Enter the data in the text box. No need to key in Customer Number because it is an auto number:

Step 3:

Click the Save Button to save the new entries to the database file:

Step 4:

Click Refresh Button and click the Last Button. You will see your new record that you have just entered.


How to work with the Close Button to close the program

How to work with the Close Button to close the program

To work with the Close Button to close the program

Step 1:

To close the program during runtime, you can add a button to the form:

Step 2:

Set caption of the button properties:

Caption=Close

Step 3:

Double click on the button and write down the programming codes:

Private Sub Command9_Click()

Close

End Sub

By clicking on the 'Close' button, a user can close the program directly.


How to work with the Refresh Button to refresh database

How to work with the Refresh Button to refresh database

To work with the Refresh Button to refresh database

Step 1:

To refresh the database, you can add a button to the form:

Step 2:

Set the caption of the button properties:

Caption=Refresh

Step 3:

Double click on the button and write down the programming codes:

Private Sub Command8_Click()

Adodc1.Refresh

End Sub

After clicking on the 'Refresh' button, the data will be refreshed to reflect the most updated data from the database file.

How to work with the Delete Button to delete data

How to work with the Delete Button to delete data

To work with the Delete Button to delete data

Step 1:

To delete data from the database, you can add a Command button to the form:

Step 2:

Set caption of the CommandButton Properties:

Caption=Delete

Step 3:

Double click on the button and write down the programming codes:

Private Sub Command7_Click()

Adodc1.Recordset.Delete

End Sub

This will delete the data from the database after clicking on the 'Delete' button.


How to work the Save Button to save to database

How to work the Save Button to save to database

To work the Save Button to save to database

Step 1:

To save data directly to database from a button, add a Command button to the form:

Step 2:

Set the Caption properties:

Caption=Save

Step 3:

Double click on the button and write down the programming codes:

Private Sub Command6_Click()

Adodc1.Recordset.Update

End Sub

This will save and update the data directly to the database file after clicking on the 'Save' button.


How to work the ADD Button to add to database

How to work the ADD Button to add to database

To work the ADD Button to add to database

ADD Button is used to add the new record to the database.

Step 1:

Add a Command button to form:

Step 2:

Set the Caption Properties:

Caption=ADD

Step 3:

Double click on the button and write down the programming codes:

Private Sub Command5_Click()

Adodc1.Recordset.AddNew

Text2.SetFocus

End Sub

In this example, the button will add the new entries from the Textbox2 directly to the database file.


How to use the EOF and BOF of database

How to use the EOF and BOF of database

To use the EOF and BOF of database

EOF = return a value that indicates whether the current record position is before the first record in a Recordset object.

BOF = return a value that indicates whether the current record position is after the last record in a Recordset object.

Step 1:

Double click on the ADODC Control:

Step 2:

Choose the Move Complete event:

Step 3:

In this example, write down the programming codes:

Private Sub Adodc1_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)

If Adodc1.Recordset.BOF Then

Adodc1.Recordset.MoveFirst

MsgBox "This is a First Record", vbQuestion, "Warning"

End If

If Adodc1.Recordset.EOF Then

Adodc1.Recordset.MoveLast

MsgBox "This is a Last Record", vbQuestion, "Warning"

End If

End Sub

In this example, a message box will alert user if it has reached the last or first record.


How to work with the Last Button to access data

How to work with the Last Button to access data

To work with the Last Button to access data

Step 1:

To go to the last record from a Command button, add the button to the form:

Step 2:

Set the Caption properties:

Caption=Last

Step 3:

Double click on the button and write down the programming codes:

Private Sub Command4_Click()

Adodc1.Recordset.MoveLast

End Sub

This will skip to the last record after clicking on the 'Last' button.


How to work with the Next Button to access data

How to work with the Next Button to access data

To work with the Next Button to access data

Step 1:

To move to the next record, add the button to the form:

Step 2:

Set the Caption properties:

Caption=Next

Step 3:

Double click on the button and write down the programming codes:

Private Sub Command3_Click()

Adodc1.Recordset.MoveNext

End Sub

This will move to the next record after clicking on 'Next' button on the form.

How to work with Previous Button to access data

How to work with Previous Button to access data

To work with Previous Button to access data

Step 1:

To go back to a previous record, add the button to the form:

Step 2:

Set the Caption properties:

Caption=Previous

Step 3:

Double click on the button and write down the programming codes:

Private Sub Command2_Click()

Adodc1.Recordset.MovePrevious

End Sub

This will move the data to the previous record after clicking on the button.


How to work with the First Button to access data

How to work with the First Button to access data

To work with the First Button to access data

Step 1:

To move back to first record, add one Button to the Form:

Step 2:

Set the Caption Properties:

Caption=First

Step 3:

Double click on the button and write down the programming codes:

Private Sub Command1_Click()

Adodc1.Recordset.MoveFirst

End Sub

By clicking on the Command button, the data will be moved back to the first record through the ADODC control.


How to work with the ADODC Control

How to work with the ADODC Control

To work with the ADODC Control

Step 1:

At runtime, you can select Next Data by clicking on the arrow button of the ADODC Control as shown below:

Step 2:

You can Go Back (to Previous Data) as shown below:

Step 3:

Go to the last data:

Step 4:

Go to the first data:


How to set the DataField on Text Box

How to set the DataField on Text Box

To set the DataField on Text Box

Step 1:

Select the Text Box:

Step 2:

Set the DataField Properties:

Text1=CustomerNo

Text2=Name

Text3=Address

Text4=PhoneNo

Step 3:

The data will be displayed on each text box during runtime. Data is loaded from the Data Source:

How to set the Text Box DataSource

How to set the Text Box DataSource

To set the Text Box DataSource

Step 1:

Select the Text Box:

Step 2:

Set the text box DataSource. This DataSource property is connected to the Adodc, in this example.

The data source of the selected text box is set.


How to add Text Box to the Form

How to add Text Box to the Form

To add Text Box to the Form

Step 1:

Adding four text boxes to the form:

Step 2:

Set the Properties. Delete the word in the Text field:

Step 3:

4 text boxes are added to the form:


How to design the Form

How to design the Form

To design the Form

Step 1:

We can use Label to design a form.

Add four labels to the Form:

Step 2:

Set the Label properties:

Label1=Customer No

Label2=Customer Name

Label3=Customer Address

Label4=Phone No

Step 3:

The 4 labels are displayed on the form:


How to use the ADO Control to connect to the database

How to use the ADO Control to connect to the database

To use the ADO Control to connect to the database

Step 1:

Left click on the ADO Control in the Form. Choose ADO Properties.

Step 2:

Click the Build Button:

Step 3:

Select the Microsoft Jet 4.0 OLE Provider. Click Next Button:

Step 4:

Select the Database Name. Click the &ldots;. Button:

Step 5:

Select the Database in the drive. Click Open Button:

Step 6:

Click the Test Connection Button to test if the connection is correct. The message box will tell you whether the connection is successful. Click the Ok Button.

Step 7:

Click Ok Button to connect to the database.

How to set the Record Source

How to set the Record Source

To set the Record Source

Step 1:

Choose Record Source in the Properties window.

Step 2:

Choose the adCmdTable in the Command Type:

Step 3:

Choose your table.

Step 4:

Click Apply Button and Click OK Button. This will set the Record Source.

How to add the Data Source in ODBC

How to add the Data Source in ODBC

To add the Data Source in ODBC

Step 1:

Go to Control Panel in window. Click the ODBC Data Source.

Step 2:

Click Add Button:

Step 3:

Choose one driver you have used to create Database. If you used the Access to create Database, select the Access Driver. Click Finish Button.

Step 4:

Enter the Data Source Name:

Step 5:

Click the Select Button to select the Database.

Step 6:

Select the Database. Click Ok Button.

Step 7:

Click Ok Button.

This will add the Data Source in ODBC.