Access form events not quite right.

PeterBaileyUk
PeterBaileyUk used Ask the Experts™
on
I have a form that will allow the user to set some conditions and store those conditions so that a dynamic query can be made that reflects the selections.

I have 12 fields which are represented with the left most option group, when the user clicks a fieldchoice option ie bhp etc the code generates the sql for the combo. the combo default will be all periods but the option group creates the query that tells the combo the periods of data batches that are available for that data. the sql works and the combo is populated correctly but unless i select a period after the combo is selected the option group control freezes. and I am not sure why.

I want the combo sql to update but its not obligatory to go for a batch.

here is my option group code
Private Sub FrmFieldChoice_Click()
Dim db As Database
Set db = CurrentDb
Dim RstCapFieldConditions As dao.Recordset
Dim SearchCriteria As String

Dim StrQuerySelect As String
Dim StrQueryFrom As String
Dim StrQueryGroup As String
Dim StrQueryOrder As String


Set RstCapFieldConditions = db.OpenRecordset("SELECT TblClientFields.FieldName, TblClientFields.CustomVarianceTotal, TblClientFields.Client," _
& " TblClientFields.[Field Condition], TblClientFields.[Output Field], TblClientFields.Period" _
& " FROM TblClientFields" _
& " WHERE (((TblClientFields.Client)=""Cap""));")



Select Case Me.FrmFieldChoice

Case 1
TblSelected = "BHP"

Case 2
TblSelected = "CC"


Case 3
TblSelected = "Co2"

Case 4
TblSelected = "Cylinders"

Case 5
TblSelected = "Doors"

Case 6
TblSelected = "FWdGears"

Case 7
TblSelected = "GVW"

Case 8
TblSelected = "KW"

Case 9
TblSelected = "Nom"

Case 10
TblSelected = "Seats"

Case 11
TblSelected = "Valves"

Case 12
TblSelected = "WBaseType"


End Select

StrQuerySelect = "SELECT Tbl" & TblSelected & ".ChangeYearMonth"
StrQueryFrom = " FROM Tbl" & TblSelected
StrQueryGroup = " GROUP BY Tbl" & TblSelected & ".ChangeYearMonth"
StrQueryOrder = " ORDER BY Tbl" & TblSelected & ".ChangeYearMonth DESC;"

StrQuery = StrQuerySelect & StrQueryFrom & StrQueryGroup & StrQueryOrder
'Debug.Print StrQuery
Me.CBYM.RowSource = StrQuery




End Sub

Open in new window

maybe someone could advise how I deal with this.

Ive attached the db its small but if your on a mobile you might not want to download it.

frmgate and cap edit settings is the tab to look at.
the db is storing data edit changes in the individual tables and the interface is a way to look at relevant data that has changed


I am using vba
ee-example.PNG
CapComparitor.zip
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
from my iPad, so cannot download the file.

I'm not sure I understand the problem.  You say the "option group control freezes", what does that mean?

Your code looks sufficient to update the combo box based on the selection in the Option group, assuming that the left column of radio buttons are the only ones actually bound to the group.

If I were doing it , without knowing what the data in all of those various tables looks like, I would probably add a DISTINCT predicate in your SELECT statement, so you don't get duplicate values for the ChangeYearMonth field

StrQuerySelect = "SELECT DISTINCT Tbl" & TblSelected & ".ChangeYearMonth"

But this should perform the function of updating the combo.  So what doesn't work,  Is there something else besides updating the combo?

Author

Commented:
If I select cc (lets say) the combo updates for sure but if I dont actually go to the combo and decide to then click Co2 for example the option box selection is stuck.
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
Peter,

I don't see anything which would cause the option group to "stick"

What is the purpose of lines 13-16?

You appear to be opening a recordset, but you never use that recordset or close it for that matter?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
I have a table called tblclientfields and that holds the various data that will be set from here in this case its taking the field name bhp from the option group for example then looks for that row in the case so it can set the right data to the right table. so depending on the option itll get to the right table tblbhp tblcc. in these tables is the differences in data between each successive month. so if bhp previously was 100 and now is 105 it records that change this interface is used to select certain conditions ie period, size of change and create a report from that.

Author

Commented:
this way i only need one control for all the fields
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
Peter,

My point was that lines 13-16 open a recordset that never gets used in this code segment.  Ist there more code in the frame_click event than what you have posted?  Do you also have code in the frames AfterUpdate event?

Or is there perhaps code in the forms time event that is causing the problem you mention?

I'll be home shortly, so I will be able to open the file you posted.

Author

Commented:
aha ok i get what you mean yes it was used to set values in the table previously i have just taken that set out now. the behaviour is still as described, yes if you could take a peak as the code doesnt rely on the linked tables for this particular question.

Author

Commented:
ive attached a new db with that rst out
CapComparitor.zip
I'm wondering why you created so many similar tables (1 for each category) rather than a single table that included a field to identify the category.  That way you would only have a single query rather than one for each table.

Ron

Author

Commented:
its for vehicle data and this way when the table gets to big to be contained in this db I can port them off somewhere. at present its only holding 2 months worth but the tables just get far too big with millions of records.
Owner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010
Commented:
Peter,

I honestly cannot tell you what is going on.  All three of those option groups (frames) down the left side of that form are acting that way.  When you make a selection in the frame, it will not let you change that selection until you click on another radio button in another frame or in the combo box.  Then they function properly.

I created a new option group, imported all of the radio buttons from that to left frame into it, and copied your code into the After_Update event of that new frame, and when I did that, the option group and the code worked properly.

You might simply try that, but at this point, I think I would recommend creating a new database and importing everything into it, before moving on.  Check whether that makes a difference (it would if your database or form has gotten corrupted).  If not, then create new frames to replace the three you currently have.

Author

Commented:
thank you
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
Peter,

Glad to help.

Did you end up replacing the option groups, or did importing into another database solve your problem?

Author

Commented:
I replaced the option groups and now so far its working fine..thank you once again.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial