Solved

What's wrong with this code?

Posted on 2002-07-17
23
225 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:sanand
  • 10
  • 3
  • 2
  • +6
23 Comments
 
LVL 5

Expert Comment

by:rpai
ID: 7160326
Is Me.cboStSuffix a value from the combo box?
0
 

Expert Comment

by:Vasudeesha
ID: 7160334
Hi sanand

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

Bye
Vasudeesha
0
 

Author Comment

by:sanand
ID: 7160378
Thanks for your quick response, Vasudeesha.

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

Any other idea, please?

Thanks
0
 

Author Comment

by:sanand
ID: 7160383
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
 
LVL 5

Expert Comment

by:rpai
ID: 7160398
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
 

Expert Comment

by:Vasudeesha
ID: 7160402
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
 

Author Comment

by:sanand
ID: 7160434
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
 
LVL 5

Expert Comment

by:rpai
ID: 7160469
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
 
LVL 18

Expert Comment

by:mdougan
ID: 7160476
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
 

Author Comment

by:sanand
ID: 7160488
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
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 7160491
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Expert Comment

by:jsm11482
ID: 7160537
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
 

Author Comment

by:sanand
ID: 7160578
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
 

Author Comment

by:sanand
ID: 7160592
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
 

Author Comment

by:sanand
ID: 7160791
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
 
LVL 4

Expert Comment

by:TigerZhao
ID: 7161241
where your call the UpdateFullAddr()?
0
 

Expert Comment

by:ceasar70
ID: 7161476
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
 
LVL 2

Accepted Solution

by:
ventond earned 20 total points
ID: 7161797
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
 

Expert Comment

by:jsm11482
ID: 7161937
Good call ventond! That's probably it.
-josh
0
 

Author Comment

by:sanand
ID: 7162310
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
 

Author Comment

by:sanand
ID: 7162362
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
 
LVL 2

Expert Comment

by:ventond
ID: 7163050
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
 

Author Comment

by:sanand
ID: 7163090
Great solution.

TIA
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now