String values not being displayed correctly

D

DubboPete

Hi all,

I have five string values - strFrame3, strFrame13, strFrame26,
strTitle and StrTotal

I'm trying to create a strTotal that reflects the preceding four
string values depending on what is clicked in the frames, etc. I
keep getting the string that changes to show only, leaving the other
strings blank, even though there are default values loaded on open.

Here's my code on FormOpen:

Private Sub Form_Open(Cancel As Integer)

Dim strFrame3 As String
Dim strFrame13 As String
Dim strFrame26 As String
Dim strTotal As String
Dim strTitle As String

' default string values
strFrame3 = "Community"
strFrame13 = "All"
strFrame26 = "Ambulatory"
strTitle = "Default report"
strTotal = "Waiting values..."
Me.Text36 = strTotal

End Sub

Text36 displays strTotal, so on open it shows:

Waiting values...

Now, if someone clicks one of the option groups, for instance the
first option group, and chooses D&A option (2), strFrame3 should be
updated to the value shown below, and then strTotal should be
refreshed to show the update.

Here's the code for Frame3:

Private Sub Frame13_Click()

If Me.Frame13 = 1 Then
Me.Text25 = ""
ElseIf Me.Frame13 = 2 Then
Me.Text25 = "D&A"
ElseIf Me.Frame13 = 3 Then
Me.Text25 = "MH"
End If
strTotal = strTitle & ", " & strFrame3 & ", " & strFrame13 & ", "
& strFrame26
Me.Text36 = strTotal

End Sub

I am presuming that nothing else has changed, including strTitle, so
here's what I expected it to show:

Waiting values..., D&A, ,

But, I get this :

, , D&A, ,

can anyone find the fault in my code please?

TIA

DubboPete
 
G

Graham Mandeno

Hi Pete

Several points:

1. Your string declarations are *inside* your Form_Open sub so they are only
available locally in that procedure. If you want them to be available
throughout your module, then move them to the "declarations section" before
the first Function or Sub declaration.

2. The fact that you are able to refer to them elsewhere in your code
without an error indicates that you have implicit declaration enabled. This
is one of the Seven Deadly Sins and unfortunately it is enabled by default
and you need to turn it off. Do this by (a) adding "Option Explicit" as the
first line in every existing module and (b) going to Tools>Options and
clicking the "Require variable declaration" checkbox. This will
automatically insert "Option Explicit" in any new module you create.

3. When you add a new control to a form, Access gives it a meaningless name
like Text25 or Frame33. It's a really good idea to get into the habit of
renaming controls as soon as they are added, so that they are called
meaningful things such as txtTotal or opgShippingMethod.

4. You should use the AfterUpdate event of a control to respond to a change
in the control's value, not the Click event.

5. I may be wrong, but your code seems to be confusing the use of the
variables strTitle and strTotal.
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand
 

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