What's wrong with this code?

Hi Experts,

I have an A2k mdb with VB6 FE.
The table has StNum, Stdir, StName, and StSuffix
Fields.  Becuase the users need to search by the
full address, I've to add the FullAddress field also
in the table.

I am using the following code to update the full address
field on change of any of the address components.

I call this UpdateFullAddr sub on change event of each
address field.  All work fine, except the cboStSuffix
field, which neither works, nor gives any error message.

*********** code Starts here **********
Public Sub UpdateFullAddr()
                   

Dim FAddr As String
Dim StNum As String
Dim StDir As String
Dim StName As String
Dim StSuffix As String

    StNum = Me.txtStNum.Text
    StDir = Me.txtStDir.Text
    StName = Me.txtStName.Text
    StSuffix = Me.cboStSuffix  'This line does not work
   
    FAddr = StNum & " " & StDir & "." & " " & StName & " " & StSuffix
    Me.txtFullAddress = UCase(FAddr)

End Sub

*********** code Starts here **********

Any advice is appreciated.

Thanks
sanand
sanandAsked:
Who is Participating?
 
ventondConnect With a Mentor Commented:
What I bet is happening:
You have all of your change events coded to call the UpdateFullAddr Sub.
ie.
sub cboStSuffix_Change()
  updatefulladd
end sub

sub txtStDir_Change()
  updatefulladd
end sub
...
The funny thing about a combo box is that the Change event does NOT fire when you choose something from the list. The CLICK event does. This explains why it works when you type something. Typing fires the CHANGE event.
You need to add the routine:

sub cboStSuffix_Click()
  updatefulladd
end sub

0
 
rpaiCommented:
Is Me.cboStSuffix a value from the combo box?
0
 
VasudeeshaCommented:
Hi sanand

Have u tried using .Text property for combo u have used for Suffix...

Bye
Vasudeesha
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
sanandAuthor Commented:
Thanks for your quick response, Vasudeesha.

Yes, I did try the .text property which did not
work.

Any other idea, please?

Thanks
0
 
sanandAuthor Commented:
Thanks, rpai.

The values in the combo box are like:
Rd, St, Pl, Ave, etc.

But, value property of the cboStSuffix field
is not available.  The .Text property is there,
but it does not work.

Any other idea?
Thanks
0
 
rpaiCommented:
I only meant to asked if cboStSuffix is a Combo box and Me.CboStSuffix is selected from the combo box.

Please make sure that you select some value from the combo box. StSuffix can contain a blank string if at design time you have set the text property of the Combo Box to be a blank value and you do not select anything on the form.
0
 
VasudeeshaCommented:
Hi sanand

If there is no value in the combo box then that value is not updated.. Check Style property of combo.... and also try making Me.cboStSuffix.ListIndex=0

Bye
Vasudeesha
0
 
sanandAuthor Commented:
Hi Vasudeesha

I checked the Style property which is
set to "0-Dropdown Combo"

Re changing the Me.cboStSuffix to Me.cboStSuffix.Index
gives the following error:
  "Run-time error 343:
  Object not an array"

And setting it to Me.cboStSuffix.ListIndex=0
does not work either.

Thanks for your input.
sanand
0
 
rpaiCommented:
I only meant to asked if cboStSuffix is a Combo box and Me.CboStSuffix is selected from the combo box.

Please make sure that you select some value from the combo box. StSuffix can contain a blank string if at design time you have set the text property of the Combo Box to be a blank value and you do not select anything on the form.
0
 
mdouganCommented:
OK, here is the way combo boxes work.  If you are sure that the Style is Dropdown Combo, and not Dropdown List, then the Text property should be available.

The general order of operations would be this:

At form_load, you load the values into the combo using cboSTSuffix.AddItem "Rd"
cboSTSuffix.AddItem "St"
cboSTSuffix.AddItem "Ave"

The user either Types into the Text portion of the Combo, Selects from the list or leaves it blank.

In your Update function:

StSuffix = Me.cboStSuffix.Text

Is what you should use.

If you want to force the user to select from the list, and the type is Dropdown List.  Then, you'd proceed as above, except that in your update routine you'd have:  

If Me.cboStSuffix.ListIndex > -1 then
   StSuffix = Me.cboStSuffix.List(Me.cboStSuffix.ListIndex)
Else
   StSuffix = ""
End if
   

0
 
sanandAuthor Commented:
Hi rpai:

I just checked the properties of the cboStSuffix
which is a combo box and the:
List property is set to Rd, Ave, St, Blvd, etc.
The Text property is left blank.

Now when I select, say "St" from the combo box
it does not update the full address.

Some thing strange:
If I type a value in the cboStSuffix, it updates the
Full Address, but when I make a selection from the
combo box it does not.

Thanks
0
 
Arthur_WoodCommented:
when you say:
"But, value property of the cboStSuffix field
is not available.  The .Text property is there,
but it does not work."

What does "it does not work" mean?  

have you set a breakpoint on that line of code, and examined what value is being retrieved from the ComboBox?



Arthur Wood
0
 
jsm11482Commented:
Yeah, I would also suggest setting a breakpoint on the line where you set StSuffix = Me.cboStSuffix you also want to make sure that the combobox is not locked.  Do you want people to be able to add in there own street suffix? If not, change the Style property of the combobox to Dropdown List.  All you need to do to get the text property of the combobox is just what you are doing - Me.cboStSuffix - may I ask why you are using Me. instead of just cboStSuffix?

Hope this helps!
-Josh
0
 
sanandAuthor Commented:
Hi rpai:

I just checked the properties of the cboStSuffix
which is a combo box and the:
List property is set to Rd, Ave, St, Blvd, etc.
The Text property is left blank.

Now when I select, say "St" from the combo box
it does not update the full address.

Some thing strange:
If I type a value in the cboStSuffix, it updates the
Full Address, but when I make a selection from the
combo box it does not.

Thanks
0
 
sanandAuthor Commented:
Hi Arthur Wood

By
"But, value property of the cboStSuffix field
is not available.  The .Text property is there,
but it does not work."

I mean that with the change in value in the cbo
the FullAddress field does not get changed, nor
any error message is displayed.
0
 
sanandAuthor Commented:
For All:

Would it make a difference if the cboStSuffix
is tied to a field in the database?

And
The Style property of cboStSuffix set to: Dropdown Combo
and the List property in design view is set
to AV, BL, RD, ST etc.

Now this is what I want:
I want the FullAddr field updated when I select
an item from the cboStSuffix.

Why ItemData in the property sheet lists
0,0,0,0,0 and does not want me to delete it?
All combo values are entered under List property.

Please help.
TIA
0
 
TigerZhaoCommented:
where your call the UpdateFullAddr()?
0
 
ceasar70Commented:
hi
did u check if the index property of the combo is blank, because if u have a value in the index propery then your code should look like this

StSuffix = Me.cboStSuffix(x).text


where x is the number in the index propery
0
 
jsm11482Commented:
Good call ventond! That's probably it.
-josh
0
 
sanandAuthor Commented:
Thanks ventod!

This works like a charm.

So if the change event fires up only on
the combo_Click event, then why Change event
itself is available under the events?
That's confusing.  There'll always be a
tendency to use this Change_Event if it's
available.

Please assist me in understanding this
concept.

Thanks again
sanand

0
 
sanandAuthor Commented:
Thanks ventod!

This works like a charm.

So if the change event fires up only on
the combo_Click event, then why Change event
itself is available under the events?
That's confusing.  There'll always be a
tendency to use this Change_Event if it's
available.

Please assist me in understanding this
concept.

Thanks again
sanand

0
 
ventondCommented:
Why does the _Change event fire when you type and not when you choose an item from the list? (Thus causing a change)

Because, Microsoft has decreed it to be so. Really. Some Microsoft programmer, when he/she wrote the combo box, decided that the selection from the list will raise the click event and the typing of letters will raise the change event. All this happened many years ago and now we have to deal with it.
0
 
sanandAuthor Commented:
Great solution.

TIA
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.