Simple form + VBA code not working

R

rawdstorage

Hi!

I have followed the example on http://www.profsr.com/vb/vbless04.htm.
I get the error msg

Run error nr '2185'.:
It is not possible to refer to a property or method for a control
which is not highlighted/activated/tagged.
When troubleshooting the faulty line is indicated in yellow being:

"ClientName = NameTextbox.Text"

My code is as follows:
Option Compare Database
Option Explicit

Dim ClientName As String
Dim ClientCity As String

Public Sub Load_Form()
ResultLabel.Caption = " "
NameTextbox.Text = " "
CityTextbox.Text = " "
End Sub

Public Sub SubmitButton_Click()
ClientName = NameTextbox.Text
ClientCity = CityTextbox.Text

ResultLabel.Caption = "The client is " & ClientName & " and lives
in " & ClientCity & "."
End Sub

Public Sub CancelButton_Click()
Form_Load
End Sub

Public Sub ExitButton_Click()
Unload Me
End Sub


What does it really mean when a property is not highligted or
activated?
 
D

Douglas J. Steele

The website you cite is for Visual Basic, not Access. There are differences
in the controls available for forms in VB and in Access, so many examples
that work in VB cannot be copied to Access without making some changes. For
instance, while in VB you must always refer to the Text property of a
control, in Access you can only use the Text property when a control has
focus.

Remove .Text from the code (or replace it with .Value).

(I'm surprised you didn't get the error in the Form_Load event!)
 
R

rawdstorage

Thank you for your reply!
I have come to realise more and more of the differences in the
different languages. I reckon I will be returning to this forum more
than once the following days.

Actually, the error used to be in the Load_Form until I changed the
scope of the subroutines to public.

Very much obliged for the assistance. =)

Best regards,
R
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top