Form (3) – VB code to add

Now that we have placed all the items in the form, it is time to add the VB code.

Just click the “View” button and select “Code” in the drop-down menu. The shortcut for this is F7 on your keyboard.

les10_image001_en

Depending on the object that was selected at that time in the form, the code window with the code for that object is opened. Since the textbox txtNaam was selected, we give the code for this object.

les10_image002_en

Remove all the code, and it gives “General” in the “Object” box.

Clicking on the downward pointing arrow next to the “Object” box (A), gives us a list containing all objects in our form. Clicking on the downward pointing arrow next to the “Declarations” box (B), gives us a list of all possible procedures that can be applied to an object. For example, the procedure “Click” is applied to a command button.

les10_image003_en

I’ve already posted the code in the code window. In the next lesson we will discuss this, but now that we’re here, we will go test it first. Just click the “Run Sub / User Form”, or click the F5 key on your keyboard.

les10_image004_en
This opens the form. Enter the details and click the Add button.

les10_image005_en
Once you have clicked the Add button, the data in the form is deleted and added to the table.

les10_image006_en
Click the “Close” button and you will return to the Visual Basic code window.

In the next lesson we will look at the code view.

Awesome!
You've completed Lesson 10
START NEXT LESSON