VBA example - Microsoft Access: Select Case data in textboxes


VBA display data in textboxes

In this example, you will learn VBA Select Case Statement with If Else Statement to populate data in the text boxes automatically when you type the value in the first text box. When the form loads, the animation of form caption performs. The example demonstrates the Taxation form as the figure below:

 VBA example - Microsoft Access VBA Select Case Statement with VBA If Else Statement Taxation Form  

- The form has four text boxes(SubjectID, Description, Hour, Fee), and one combo box box(SubjectName).

- On the form, there is only one text box(Salary) that need to enter the data. For other three text boxes will display the data automatically after the Salary text box is filled and press Enter key. See the figure:

VBA example - Microsoft Access VBA Select Case Statement with VBA If Else Statement Taxation View Form 

To have the Taxation form, create a form in Form Design as the figure:

VBA example - Microsoft Access VBA Select Case Statement with VBA If Else Statement Taxation Design Form

-  Drag and drop four text boxes on the form.

-  Set Name properties of the text boxes:

Text boxes:

Name: txtSalary

Name: txtTaxRate

Name: txtAmount

Name: txtNetSalary

After you designed the form already, apply the VBA code below:

Option Compare Database

Option Explicit

Dim i As Integer

Dim ca As String

 

Private Sub Form_Load()

TimerInterval = 200

ca = Me.Caption

i = 0

End Sub

 

Private Sub txtTax_Enter()

If txtSalary <> "" Then

   Select Case Val(txtSalary)

        Case Is >= 2000

txtTax = 0.3

        TaxAmount

                 NetSalary

       Case Is >= 1500

txtTax = 0.25

TaxAmount

NetSalary

       Case Is >= 1000

txtTax = 0.2

                TaxAmount

                NetSalary

       Case Is >= 900

                txtTax = 0.15

                TaxAmount

                NetSalary

       Case Is >= 600

                txtTax = 0.1

                TaxAmount

                NetSalary

       Case Is >= 450

                txtTax = 0.07

                TaxAmount

                NetSalary

   Case Else

                txtTax = 0.05

                TaxAmount

                NetSalary

  End Select

End If

End Sub

 

Private Sub Form_Timer()

If i < Len(ca) Then

   i = i + 1

   Me.Caption = Left(ca, i)

Else: i = 0

End If

End Sub

 

Sub NetSalary()

txtNetSalary = Val(txtSalary) - Val(txtSalary * txtTax)

End Sub

 

Sub TaxAmount()

txtTaxAmount = Val(txtSalary * txtTax)

End Sub



Comments




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.