473,395 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Why does selecting item on combo with callback function cause next callback to fail?

So, I have two comboboxes on my form. One has a vlaue list (A), then other uses a callback function to populate (B) items based on the combo A selection. If I select something in A, then the function correctly populates B. I can do this over and over. However, if I select an item in B, then go back to A to select a different filter, the callback function does not populate B. One thing I noticed was that the combobox.value is still set to the selected value, but clearing that does not help. Ideas?
Expand|Select|Wrap|Line Numbers
  1.  
  2. COMBOBOX A AFTER UPDATE
  3. Private Sub cmb_Svc_Section_AfterUpdate()
  4.  
  5.     Redraw_Form
  6.  
  7.     Application.Echo False
  8.  
  9.     With Me![cmb_Provider]
  10.         .RowSourceType = "Fill_Assigned_Provider_List"
  11.         .RowSource = ""
  12.     End With
  13.  
  14.     Application.Echo True
  15.  
  16.  
  17. End Sub
  18.  
  19. COMBOBOX B CALLBACK FUNCTION
  20.  
  21. Function Fill_Assigned_Provider_List(fld As Control, ID As Variant, row As Variant, col As Variant, code As Variant) As Variant
  22.     Static Provider_Assigned_List() As Variant
  23.     Static ProvCount As Integer
  24.  
  25.  
  26.     Const twips = 1440
  27.  
  28.     Select Case code
  29.  
  30.         Case acLBInitialize                ' Initialize.
  31.             DW_Connect
  32.  
  33.  
  34.             StrSQL = "Select * from dim.Provider where InactivationDate is null and ServiceSection is not null;"
  35. '            rs_Provider.CursorLocation = adUseServer
  36.             rs_Provider.Open StrSQL, DWConn, adOpenKeyset, adLockOptimistic, adCmdText
  37.  
  38.             rs_Provider.MoveLast
  39.             rs_Provider.MoveFirst
  40.  
  41.             ReDim Preserve Provider_Assigned_List(rs_Provider.RecordCount, 1) As Variant
  42.  
  43.             Fill_Assigned_Provider_List = True
  44.  
  45.  
  46.             ProvCount = 0
  47.  
  48.             For chkitm = 0 To rs_Provider.RecordCount - 1
  49.                 If (Not IsNull(Me.cmb_Svc_Section) And rs_Provider.Fields("ServiceSection") = Me.cmb_Svc_Section) Or (IsNull(Me.cmb_Svc_Section)) Then
  50.                     Provider_Assigned_List(ProvCount, 0) = rs_Provider.Fields("ProviderSID")
  51.                     Provider_Assigned_List(ProvCount, 1) = rs_Provider.Fields("StaffName")
  52.                     ProvCount = ProvCount + 1
  53.                 End If
  54.                 rs_Provider.MoveNext
  55.             Next chkitm
  56.  
  57.  
  58.         Case acLBOpen                        ' Open.
  59.             Fill_Assigned_Provider_List = Timer
  60.  
  61.         Case acLBGetFormat
  62.             Fill_Assigned_Provider_List = -1
  63.  
  64.         Case acLBGetRowCount            ' Get number of rows.
  65.             Fill_Assigned_Provider_List = ProvCount
  66.  
  67.         Case acLBGetColumnCount    ' Get number of columns.
  68.             Fill_Assigned_Provider_List = 2
  69.  
  70.         Case acLBGetColumnWidth    ' Column width.
  71.             Select Case col
  72.                 Case 0:
  73.                     Fill_Assigned_Provider_List = 0
  74.                 Case 1:
  75.                     Fill_Assigned_Provider_List = 3 * twips
  76.             End Select
  77.  
  78.  
  79.         Case acLBGetValue                    ' Get data.
  80.  
  81.             Fill_Assigned_Provider_List = Provider_Assigned_List(row, col)
  82.  
  83.         Case acLBEnd
  84.             DWConn.Close
  85.             rs_Provider.Close
  86.             Erase Provider_Assigned_List
  87.  
  88.     End Select
  89. End Function
  90.  
  91.  
Feb 10 '11 #1

✓ answered by ADezii

Actually, I was just looking at this Thread and thinking quite the opposite. To me it was apparent that the problem resided somewhere in the AfterUpdate() Event of B and was thinking along the lines of reopening an existing Connection which may be causing the problem, but was obviously wrong. In any event, nice job on figuring it out.

P.S. - Now that you have resolved the problem, you may wish to consider replacing
Expand|Select|Wrap|Line Numbers
  1. With Me![cmb_Provider] 
  2.   .RowSourceType = "Fill_Assigned_Provider_List" 
  3.   .RowSource = "" 
  4. End With 
with
Expand|Select|Wrap|Line Numbers
  1. Me![cmb_Provider].Requery
in the AfterUpdate() Event of cmb_Svc-Section. Not sure, but it may be more efficient than redefining the Callback to populate cmb_Provider.

8 1572
ADezii
8,834 Expert 8TB
Try NOT Erasing the contents of the Array in Line #86, and see what happens, namely:
Expand|Select|Wrap|Line Numbers
  1. 'Erase Provider_Assigned_List         Comment Line #86
This is how Access, requests, and receives its Data for the specific Row/Column combination as in Line #81:
Expand|Select|Wrap|Line Numbers
  1. Case acLBGetValue                    ' Get data. 
  2.   Fill_Assigned_Provider_List = Provider_Assigned_List(row, col)
Feb 10 '11 #2
OK, I will give this a shot. I do realize that the acLBGetValue is where the data is being placed in the control, but the code never goes there when it should be.
Feb 10 '11 #3
Nope, no better. Removing ERASE line does not affect the content of the combobox. It still ends up blank.

I followed code in the callback function. Once I select a item in box B, then select the Box A (even before I make a selection) the callback function is called by the control for the following codes in sequence (By breakpoint check on line 28):
6, 7, 6, 7, 6, 7

After this I make a selection and the callback gets thse codes in sequence:
8,9

Then the thread passes ot the box A Afterupdate subroutine. It walks through the steps until the box A requery, where it jumps back into the callback function with the code 0 then jumos out of the routine and back to the form.

So, it never attempts to refill the box B from my selection in box A once I have made a selection in box B.
Feb 10 '11 #4
ADezii
8,834 Expert 8TB
Is there any Code in the AfterUpdate() Event of Combo B, and if so, what is it?
Feb 10 '11 #5
Yes there is. The code connects to another SQL table and then changes the size and layout of th eform to accomodate data from that other table.

Expand|Select|Wrap|Line Numbers
  1.  Private Sub cmb_Provider_AfterUpdate()
  2.     Redraw_Form
  3.     DW_Connect
  4.  
  5.     rs_ScoreData.CursorLocation = adUseServer
  6.  
  7.     strSQLScore = "Select oppesid, measure_ClassSID,measure_Class, Measure, Benchmark, Max(ScoreDate) as Last_Date, sum(Numerator) as Num, sum(Denominator) as Denom from dbo.vw_Score_Result where ProviderSID = " & Me.cmb_Provider.Column(0) & " and ActiveDate <= '" & Me.txt_End_Date & "' and (inactivedate is null or (inactivedate > '" & Me.txt_Start_Date & "' and inactivedate < '" & Me.txt_End_Date & "')) group by oppesid, measure_ClassSID,measure_Class, Measure, Benchmark order by measure_ClassSID, Measure;"
  8.     rs_ScoreData.Open strSQLScore, DWConn, adOpenKeyset, adLockOptimistic, adCmdText
  9.  
  10.  
  11.     Set TmpTblScore_Data = CurrentDb.OpenRecordset("Score", dbOpenDynaset, dbSeeChanges)
  12.     Do While Not TmpTblScore_Data.EOF
  13.         TmpTblScore_Data.Delete
  14.         TmpTblScore_Data.MoveNext
  15.     Loop
  16.  
  17.     Do While Not rs_ScoreData.EOF
  18.         TmpTblScore_Data.AddNew
  19.         TmpTblScore_Data.Fields("OPPESID") = rs_ScoreData.Fields("OPPESID")
  20.         TmpTblScore_Data.Fields("Measure_ClassSID") = rs_ScoreData.Fields("Measure_ClassSID")
  21.         TmpTblScore_Data.Fields("Measure_Class") = rs_ScoreData.Fields("Measure_Class")
  22.         TmpTblScore_Data.Fields("Measure") = rs_ScoreData.Fields("Measure")
  23.         TmpTblScore_Data.Fields("Benchmark") = rs_ScoreData.Fields("Benchmark")
  24.         TmpTblScore_Data.Fields("Last_Date") = rs_ScoreData.Fields("Last_Date")
  25.         TmpTblScore_Data.Fields("Num") = rs_ScoreData.Fields("Num")
  26.         TmpTblScore_Data.Fields("Denom") = rs_ScoreData.Fields("Denom")
  27.         TmpTblScore_Data.Update
  28.         rs_ScoreData.MoveNext
  29.     Loop
  30.  
  31.  
  32.     TopPos = 0
  33.  
  34.     If TmpTblScore_Data.RecordCount > 0 Then
  35.         Set rs_Score_Class = CurrentDb.OpenRecordset("SELECT Measure_ClassSID, Count(OPPESID) AS Num_Rec FROM Score GROUP BY Measure_ClassSID;", dbOpenDynaset, dbSeeChanges)
  36.         rs_Score_Class.MoveFirst
  37.         Do While Not rs_Score_Class.EOF
  38.             Select Case rs_Score_Class.Fields("Measure_ClassSID")
  39.                 Case 1
  40.                     Me.subfrm_First.Move Left:=0, Top:=TopPos, Height:=(0.65 + (rs_Score_Class.Fields("Num_Rec") * 0.425)) * twips
  41.                     Me.subfrm_First.Visible = True
  42.                     Me.subfrm_First.Requery
  43.                     TopPos = TopPos + ((0.65 + (rs_Score_Class.Fields("Num_Rec") * 0.425)) * twips)
  44.                     Me.InsideHeight = Me.InsideHeight + ((0.65 + (rs_Score_Class.Fields("Num_Rec") * 0.425)) * twips)
  45.                 Case 2
  46.                     Me.subfrm_Second.Move Left:=0, Top:=TopPos, Height:=(0.65 + (rs_Score_Class.Fields("Num_Rec") * 0.425)) * twips
  47.                     Me.subfrm_Second.Visible = True
  48.                     Me.subfrm_Second.Requery
  49.                     TopPos = TopPos + ((0.65 + (rs_Score_Class.Fields("Num_Rec") * 0.425)) * twips)
  50.                     Me.InsideHeight = Me.InsideHeight + ((0.65 + (rs_Score_Class.Fields("Num_Rec") * 0.425)) * twips)
  51.                 Case 3
  52.  
  53.                     Me.subfrm_Third.Move Left:=0, Top:=TopPos, Height:=(0.65 + (rs_Score_Class.Fields("Num_Rec") * 0.425)) * twips
  54.                     Me.subfrm_Third.Visible = True
  55.                     Me.subfrm_Third.Requery
  56.                     TopPos = TopPos + ((0.65 + (rs_Score_Class.Fields("Num_Rec") * 0.425)) * twips)
  57.                     Me.InsideHeight = Me.InsideHeight + ((0.65 + (rs_Score_Class.Fields("Num_Rec") * 0.425)) * twips)
  58.                 Case 4
  59.  
  60.                     Me.subfrm_Fourth.Move Left:=0, Top:=TopPos, Height:=(0.65 + (rs_Score_Class.Fields("Num_Rec") * 0.425)) * twips
  61.                     Me.subfrm_Fourth.Visible = True
  62.                     Me.subfrm_Fourth.Requery
  63.                     TopPos = TopPos + ((0.65 + (rs_Score_Class.Fields("Num_Rec") * 0.425)) * twips)
  64.                     Me.InsideHeight = Me.InsideHeight + ((0.65 + (rs_Score_Class.Fields("Num_Rec") * 0.425)) * twips)
  65.                 Case 5
  66.  
  67.                     Me.subfrm_Fifth.Move Left:=0, Top:=TopPos, Height:=(0.65 + (rs_Score_Class.Fields("Num_Rec") * 0.425)) * twips
  68.                     Me.subfrm_Fifth.Visible = True
  69.                     Me.subfrm_Fifth.Requery
  70.                     TopPos = TopPos + ((0.65 + (rs_Score_Class.Fields("Num_Rec") * 0.425)) * twips)
  71.                     Me.InsideHeight = Me.InsideHeight + ((0.65 + (rs_Score_Class.Fields("Num_Rec") * 0.425)) * twips)
  72.                 Case 6
  73.  
  74.                     Me.subfrm_Sixth.Move Left:=0, Top:=TopPos, Height:=(0.65 + (rs_Score_Class.Fields("Num_Rec") * 0.425)) * twips
  75.                     Me.subfrm_Sixth.Visible = True
  76.                     Me.subfrm_Sixth.Requery
  77.                     TopPos = TopPos + ((0.65 + (rs_Score_Class.Fields("Num_Rec") * 0.425)) * twips)
  78.                     Me.InsideHeight = Me.InsideHeight + ((0.65 + (rs_Score_Class.Fields("Num_Rec") * 0.425)) * twips)
  79.                 Case 7
  80.  
  81.                     Me.subfrm_Seventh.Move Left:=0, Top:=TopPos, Height:=(0.65 + (rs_Score_Class.Fields("Num_Rec") * 0.425)) * twips
  82.                     Me.subfrm_Seventh.Visible = True
  83.                     Me.subfrm_Seventh.Requery
  84.                     TopPos = TopPos + ((0.65 + (rs_Score_Class.Fields("Num_Rec") * 0.425)) * twips)
  85.                     Me.InsideHeight = Me.InsideHeight + ((0.65 + (rs_Score_Class.Fields("Num_Rec") * 0.425)) * twips)
  86.                 Case 8
  87.  
  88.                     Me.subfrm_Eight.Move Left:=0, Top:=TopPos, Height:=(0.65 + (rs_Score_Class.Fields("Num_Rec") * 0.425)) * twips
  89.                     Me.subfrm_Eight.Visible = True
  90.                     Me.subfrm_Eight.Requery
  91.                     TopPos = TopPos + ((0.65 + (rs_Score_Class.Fields("Num_Rec") * 0.425)) * twips)
  92.                     Me.InsideHeight = Me.InsideHeight + ((0.65 + (rs_Score_Class.Fields("Num_Rec") * 0.425)) * twips)
  93.             End Select
  94.             rs_Score_Class.MoveNext
  95.         Loop
  96.  
  97.     End If
  98.  
  99.     TmpTblScore_Data.Close
  100.  
  101.     rs_ScoreData.Close
  102.  
  103.  
  104.     If Me.subfrm_First.Visible = True Then Me.subfrm_First.SetFocus
  105.  
  106.     DWConn.Close
  107.  
  108.  
  109.  
  110.     End Sub
  111.  
  112.  
Feb 10 '11 #6
Figured it out. I was closing my ADO connection eveytime I used it so I could try and release resources I was not using. Everytime I closed the connection through a DWConn.Close, I was wiping out my provider list. My thought was that each time I called the connection for an ADO call it was a seperate connection. Guessed wrong.

Thanks for your help. Your insistence on looking at Box B afterupdate pointed me in the right direction.
Feb 10 '11 #7
ADezii
8,834 Expert 8TB
Actually, I was just looking at this Thread and thinking quite the opposite. To me it was apparent that the problem resided somewhere in the AfterUpdate() Event of B and was thinking along the lines of reopening an existing Connection which may be causing the problem, but was obviously wrong. In any event, nice job on figuring it out.

P.S. - Now that you have resolved the problem, you may wish to consider replacing
Expand|Select|Wrap|Line Numbers
  1. With Me![cmb_Provider] 
  2.   .RowSourceType = "Fill_Assigned_Provider_List" 
  3.   .RowSource = "" 
  4. End With 
with
Expand|Select|Wrap|Line Numbers
  1. Me![cmb_Provider].Requery
in the AfterUpdate() Event of cmb_Svc-Section. Not sure, but it may be more efficient than redefining the Callback to populate cmb_Provider.
Feb 10 '11 #8
Thanks again. I will look at making the change. It was an earlier suggestion of yours to try and make another part of this work.
Feb 11 '11 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Edward | last post by:
Access 2k FE/BE My application allows users to enter employee hours against rotas (i.e. who is rostered on, and when). They further want a function to output a report showing the number of...
8
by: kurtcobain1978 | last post by:
-------------------------------------------------------------------------------- I need to do the exactly same thing in VB.NET. Load a unmanaged C DLL dynamically and then call a function in...
7
by: Kirk McDonald | last post by:
Let's say I have a function that takes a callback function as a parameter, and uses it to describe an iteration: def func(callback): for i in : callback(i) For the sake of argument, assume...
5
by: sajin | last post by:
Hi All.. We are using VB .Net 2005 for implementing an API. API needs to generate events. For this client wants us to use Windows Callback (delegate implementation). The intention of using...
11
by: The Frog | last post by:
Hi all, Maybe I am just missing something simple here, but I seem to have an issue with a callback function in A97 that is used to fill a Listbox with values. The first time the callback...
6
by: smmk25 | last post by:
Before I state the problem, I just want to let the readers know, I am knew to C++\CLI and interop so please forgive any newbie questions. I have a huge C library which I want to be able to use in...
2
by: Pradeep | last post by:
Hi all, Can any one explain me what is callback function.... I have written some code after reading some tutorials from internet... But I am not sure is it a right way to write a call back...
3
by: jack113256 | last post by:
Hi everyone: I have a question in using Callback function, there is my code: /******* code start *********/ #include <stdio.h> void a(); void b(); void run();
40
by: Angus | last post by:
Hello I am writing a library which will write data to a user defined callback function. The function the user of my library will supply is: int (*callbackfunction)(const char*); In my...
6
by: jmDesktop | last post by:
In a function that takes another function (function pointer) as a argument, or the callback function, which is the one that "calls back"? I'm having a hard time understanding the language. Am I...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.