Double jeopardy

John Sh

Active member
Local time
Tomorrow, 06:49
Joined
Feb 8, 2021
Messages
574
I have two problems in the attached sample.
1. If I leave the recordsource statement un-commented, the code goes straight to the "Createdby_Gotfocus" event, runs it then returns to the onload event.
Comment it out and the code runs as expected.
2. With the "on error resume next" statements commented out the code crashes as it tries to set focus to a previously focused control.
Remove the comments and it works.

The first problem only seems to happen with this test code.

I encounter the second problem often when moving to the next control without actually selecting something in a combobox.
I don't like to use the on error construct as it just hides a problem but I am unable to find an alternate that avoids this.

I use a construct like
Code:
me.cboX = me.cboX.itemdata(0)
if nz(me.cboX.itemdata(1),"") ="" then
    me.cboNext.setfocus
else
    me.cboX.dropdown
end if
 

Attachments

exactly why are you doing this.
what i can see it you are always Altering/Editing the first record of
your table Others. because you are setting both both comboboxes
to the first elements of their list. If for example you select the second items on both
combobox, when you open the form, you alter them by selecting the first items.

if that is the behaviour you want to a New record, do it if you are in New record.
 
I don't see your test code above in the example and I'm not sure what your trying to do.
It would seem you could just use the onload event to do all those things without iterating through the controls using got focus.

TempVars!Genus = "Acacia"
TempVars!Species = "binervia"
Me.Visible = True
Me.RecordSource = "Others"
Me.cbogenus.Requery
Me.cbogenus = Me.cbogenus.ItemData(0)
Me.cboEpithet.Requery
Me.cboEpithet = Me.cboEpithet.ItemData(0)
Me.cbocreatedby.Requery
Me.cbocreatedby = Me.cbocreatedby.ItemData(0)
 
exactly why are you doing this.
what i can see it you are always Altering/Editing the first record of
your table Others. because you are setting both both comboboxes
to the first elements of their list. If for example you select the second items on both
combobox, when you open the form, you alter them by selecting the first items.

if that is the behaviour you want to a New record, do it if you are in New record.
Hi.
I put the two tempvars in there to feed the comboboxes.
In real life they would be instantiated in a separate form with the current record's genus and species.
The code supplied is just the problem bit, the real code uses the genus and species info to select one, or more, images of that specific plant.
There are, currently, some 9,000 images so what you are seeing is just a tiny sample.
 
I don't see your test code above in the example and I'm not sure what your trying to do.
It would seem you could just use the onload event to do all those things without iterating through the controls using got focus.

TempVars!Genus = "Acacia"
TempVars!Species = "binervia"
Me.Visible = True
Me.RecordSource = "Others"
Me.cbogenus.Requery
Me.cbogenus = Me.cbogenus.ItemData(0)
Me.cboEpithet.Requery
Me.cboEpithet = Me.cboEpithet.ItemData(0)
Me.cbocreatedby.Requery
Me.cbocreatedby = Me.cbocreatedby.ItemData(0)
Thanks.
I have, in fact, done just that but I have other situations where there may. or may not, be multiple results of the requery.
If there is only one result I need the program to progress to the next combo automatically.
If there is more than one result then the dropdown is activated.
In the case where there are sequential single item results the code will progress normally until it gets to a stage as indicated in the attachment with the "on error" statements commented out.
The code in the attachment is, by itself, frivolous but it demonstrates a problem to which I would like a solution..
John
 

Users who are viewing this thread

Back
Top Bottom