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 DatabaseSet db = CurrentDbDim RstCapFieldConditions As dao.RecordsetDim SearchCriteria As StringDim StrQuerySelect As StringDim StrQueryFrom As StringDim StrQueryGroup As StringDim StrQueryOrder As StringSet 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.FrmFieldChoiceCase 1TblSelected = "BHP"Case 2TblSelected = "CC"Case 3TblSelected = "Co2"Case 4TblSelected = "Cylinders"Case 5TblSelected = "Doors"Case 6TblSelected = "FWdGears"Case 7TblSelected = "GVW"Case 8TblSelected = "KW"Case 9TblSelected = "Nom"Case 10TblSelected = "Seats"Case 11TblSelected = "Valves"Case 12TblSelected = "WBaseType"End SelectStrQuerySelect = "SELECT Tbl" & TblSelected & ".ChangeYearMonth"StrQueryFrom = " FROM Tbl" & TblSelectedStrQueryGroup = " GROUP BY Tbl" & TblSelected & ".ChangeYearMonth"StrQueryOrder = " ORDER BY Tbl" & TblSelected & ".ChangeYearMonth DESC;"StrQuery = StrQuerySelect & StrQueryFrom & StrQueryGroup & StrQueryOrder'Debug.Print StrQueryMe.CBYM.RowSource = StrQueryEnd Sub
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'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
But this should perform the function of updating the combo. So what doesn't work, Is there something else besides updating the combo?
PeterBaileyUk
ASKER
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 Fye
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?
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.
PeterBaileyUk
ASKER
this way i only need one control for all the fields
Dale Fye
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.
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.
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.
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.
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?