Combobox default- works but gives error at the same time?? (1 Viewer)

Margarita

Registered User.
Local time
Today, 17:58
Joined
Aug 12, 2011
Messages
185
Hello,
I am trying to set the default value of one of the columns in a 3-column combobox.

PHP:
Private Sub Form_Load()
‘some calculations to arrive at CounterNum here … 
 
CounterNum = rs_getCounter.Fields(0)
 
CounterNumCombo.Column(2).DefaultValue = CounterNum - 1
 
End Sub

The strange thing is- when I open the form, I do see the combobox defaulting to the value I want, BUT it gives me RunTime error 424: Object Required and highlights the last line in the sub.

Does anyone have an explanation for this? If it defaults, why does it give me an error? How can I get rid of it?

Thank you!
 

khodr

Experts still Learn
Local time
Tomorrow, 00:58
Joined
Dec 3, 2012
Messages
112
sometimes i get this kind of problems and when everything is going fine in the form i just point the code to exit on error, try and set your code as:
Private Sub Form_Load()
On Error Goto err_handler

CounterNum
= rs_getCounter.Fields(0
)

CounterNumCombo.Column(2).DefaultValue = CounterNum -
1
err_handler:

Exit sub
End Sub
 

Margarita

Registered User.
Local time
Today, 17:58
Joined
Aug 12, 2011
Messages
185
Hello, I tried your suggestion just now. Unfortunately, the default value now gets skipped. It doesn't give me an error, but the form opens with setting the default value.
I'll post back if I find a solution.

Thanks for your suggestion!
 

khodr

Experts still Learn
Local time
Tomorrow, 00:58
Joined
Dec 3, 2012
Messages
112
I don't know exactly what for is your combo, maybe if you write more information I can try buildup the code and test it for you... :)
 

Margarita

Registered User.
Local time
Today, 17:58
Joined
Aug 12, 2011
Messages
185
I don't know exactly what for is your combo, maybe if you write more information I can try buildup the code and test it for you... :)


Hello,
Thank you for the offer! Luckily, I finally got it to default without an error like this:

PHP:
CounterNumlistbox.DefaultValue = CounterNumlistbox.ItemData(counternum - 1)


I'm pretty happy that it now works. However, now I have a problem with capturing the change if the user picks something other than the default value.
I have several unbound fields whose values are calculated in the form's on load event based on the default value of CounterNumListbox. When the user picks a new value from the listbox, I want the fields to just recalculate on their own. I tried putting me.refresh in the form's on current and after update events, as well as the listbox after update and on click events. It doesn't help. The values in the calculated textboxes just stay the same- the calculations aren't repeared for the new value in the listbox.
Which event do I use to make those controls recalculate based on the new chosen listbox value?

Thank you!
 

khodr

Experts still Learn
Local time
Tomorrow, 00:58
Joined
Dec 3, 2012
Messages
112
Have you wrote the me.refresh on the after update event or the code itself, because
If you write the code itself on the after update event then it must update the combo box as per the code values.
 

Margarita

Registered User.
Local time
Today, 17:58
Joined
Aug 12, 2011
Messages
185
Have you wrote the me.refresh on the after update event or the code itself, because
If you write the code itself on the after update event then it must update the combo box as per the code values.


Yes, I got the refresh to work as follows:

-The code with the actual calculations for the textbox in question is contained in the form's OnCurrent event. When the form loads for the first time with the default value in CounterNumListbox, the textbox is calculated correctly.

-the listbox AfterUpdate event calls the Form Current event and the textbox is correctly recalculated every time a new listbox value is chosen.

Thank you.
 

khodr

Experts still Learn
Local time
Tomorrow, 00:58
Joined
Dec 3, 2012
Messages
112
You can also try to use the requery command
Me.requery but be careful when you use the requery then your record will go back the first record as it will requery the whole table you have then to create another code to bring you back to the current record and that is easy you need to create unbound combo to save the current record number and then apply the go to findrecord command to find the record number which you stored in the unbound combo and after bringing you back to the record the code will be applied on the chosen controls
 

Margarita

Registered User.
Local time
Today, 17:58
Joined
Aug 12, 2011
Messages
185
Oy! That sounds too complicated for my simple little set up. It's very clever- I will save your idea for reference for other forms. I haven't thought of making a separate control to hold the current record that I want to return to after re-querying. Creating new objects is something I think of last. For some reason, my brain never goes down that path. Instead I always seem to want to find some magical out of the box function that will take care of everything for me. BUt I guess sometimes you just have to get your hands dirty..
Anyway, thank you very much for your suggestions and for sticking with this thread. I really appreciate the time people in this forum are taking to help out people like me who are slow learners!
 

khodr

Experts still Learn
Local time
Tomorrow, 00:58
Joined
Dec 3, 2012
Messages
112
You are most welcome
And as far as you understood what I wrote then that means you know what am talking about anyway access will never perfume out data by magic you have always to plan it simple and insist on access to do it by telling him so many thing and direct your codes as your magic tools and then it will be magic to get what you want you can look at my group in this forum and you might get things from there you need for your database
 

Margarita

Registered User.
Local time
Today, 17:58
Joined
Aug 12, 2011
Messages
185
You are most welcome
And as far as you understood what I wrote then that means you know what am talking about anyway access will never perfume out data by magic you have always to plan it simple and insist on access to do it by telling him so many thing and direct your codes as your magic tools and then it will be magic to get what you want you can look at my group in this forum and you might get things from there you need for your database

Thank you very much, I most definitely will!
 

Users who are viewing this thread

Top Bottom