Access 2010: Updating a Combo Box Value but the OnChange() Code is not Executing - ms-access-2010

I have a combo box for selecting contact names. OnChange, it is supposed to trigger a requery of a list, so that the query filter updates. When I use the combobox pulldown, it works perfectly, but when I update the combo box from a secondary form, it does not work.
I am using arguments on the DoCmd.OpenForm To open the secondary form (which is a search form):
Set ctrl = Me.txtContactName
DoCmd.OpenForm "FindContactForm", , , , , , Me.Form.Name & ";" & ctrl.Name
The main form code is:
Private Sub txtContactName_Change()
MsgBox "Change Ocurred"
Me.listCallHistory.Requery
Refresh
End Sub
It should be noted that the debugging msgBox only appears when I use the combobox manually, so I must not be triggering the Change event when updating the combobox using the secondary form.
The secondary form code is:
Private Sub listContacts_DblClick(Cancel As Integer)
If IsNull(Me.listContacts.Column(0)) Then Exit Sub
If Not IsNull(Me.OpenArgs) Then
arrSplitStrings = Split(Me.OpenArgs, ";")
Forms(arrSplitStrings(0)).Controls(arrSplitStrings(1)).Value = Me.listContacts.Column(0)
DoCmd.Close
End If
End Sub
I'd appreciate any help, both in understanding why the onChange event is not ocurring, and also on how to implement a solution. My goal is to be able to use this search form from multiple parent forms, so I don't want to hardcode the parent form or control into it. It should be noted, that I can successfully requery the list from the search form, but that starts deviating from the goal; or requires an extra parameter to be passed and parsed. It'd work, but I'd like to understand what is going on.

Related

multiple upload, ajax control

im trying to upload multiple file and save all the files in a data table.
the data table is storing only one file.
Help me to solve, im having error in the else part. dtupload is highlighted
Below is what I have tried:
Private Sub AjaxFileUpload1_UploadComplete(sender As Object, e As AjaxControlToolkit.AjaxFileUploadEventArgs) Handles AjaxFileUpload1.UploadComplete
Try
dt.Rows.Add(UploadDocPath, UploadDoc)
MsgBox(dt.Rows.Count.ToString)
Else
dt.Rows.Add(UploadDocPath, UploadDoc)
End If
Catch ex As Exception
End Try
End Sub
Well, you in ONE local routine create a table, add a row. And then the routine finishes and all the values, variables now go out of scope. Then that routine will be called again if a 2nd file is up-loaded, and you re-create the table. The variables in that routine (and in fact ANY routine - heck even if this was not asp.net go out of scope when the routine finishes.
At least with a desktop application you could declare the table at the form level (not sub routine level) and then you could add a new row to that temp table variable. But, with asp.net, then your web page is "state less". That means all variables ONLY have their state when code runs. The instant that code is finished, then all state in the code behind is lost.
But I am somewhat perplexed that you would think the data table would persist for each call? Perhaps you only want the var dtUpload to exist in the lifetime of each separate time that routine is called? But, then again you do nothing with the table????
So, for each file up-loaded? That routine gets called.
So, lets assume 5 files are to be up-loaded.
Taking a really wild guess? I would assume we want that table/array to build up over time.
So, we need to ensure that the dtUpload table can "live" beyond a single page cycle and round trip.
So, lets save/place/put/park the dtUpload table that can live "beyond" that one routine.
It really depends on what you want to do with that list after all is said and done?
Since the table is small? Then you could certainly in the forms on-load event create that table with no rows and shove it into say the Session(). Then as each file up-loads you could shove the file name into that array.
So, your code could work like this:
In on-load event only FIRST time, create the dtUpload table. And then shove/save it into the session().
So, our on-load would look like this:
If IsPostBack = False Then
' fist time page load - create our table
Dim dtUpload As New DataTable
dtUpload.Columns.Add("PATH")
dtUpload.Columns.Add("FILENAME")
Session("FileList") = dtUpload
End If
Ok, so when the page loads (first time only), we create the dtTable and THEN save it in the session.
Now, in the file upload done event, grab the table from session, add the row (file + path).
And note HOW we don't have to shove the dtUpload table BACK into the session! (it is now a persisting object in our session).
Ok, so now our single file load event (when done) can/will look like this:
Protected Sub AjaxFileUpload1_UploadComplete(sender As Object,
e As AjaxControlToolkit.AjaxFileUploadEventArgs) Handles AjaxFileUpload1.UploadComplete
Dim dtUpload As DataTable = Session("FileList")
Dim strPath As String = "c:\Test\MyUpload\"
Dim strFile As String = e.FileName
dtUpload.Rows.Add(strPath, strFile)
AjaxFileUpload1.SaveAs(strPath & strFile)
End Sub
So, note how we add the one row to the table. (and we don't as noted have to shove the object back into the session - dtUpload in this case is in effect a object pointing to persisting dtUpload table we placed into Session().
Ok, so, now lets say all 5 files are done.
Well, you now have to decide what you want to do with the dtUpload table you have?
Perhaps we want to display all the files?
Well, keep in mind that the web page does not do a post back.
But, lets assume we now want to display all files.
Drag onto the form a datagrid control.
Drag onto the form a button.
So, we now have this:
Then hit up-load, you get this:
When you click on the the button, you can run this code:
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.GridView1.DataSource = Session("FileList")
Me.DataBind()
End Sub
And now click on that button?
And you see this:
Now here is a really huge, large, massive, VERY important reason why placed that button on the form. The reason of course is when the ajax upload is all done?
The web page does NOT do a post back. So, that is where the button above comes into play.
By clicking the button, then our code stub runs, we fill the gridview, and then of course the page makes the round trip and re-displays our file list.
Now, we could have the final CLient side ajaxfileupload event click on that button for us, and thus in place of the user clicking that button to continue?
You can have client side code click on that button for you.
So, set the OnClientUpLoadCompleteAll to the js routine:
<script>
function uerror() {
alert('upload error');
}
function myalldone() {
var btn = document.getElementById('<%=Button1.ClientID%>');
btn.click();
}
</script>
So it will now click that button (you could even set style="display:none" for the button. So, now you have a final routine server side, but with a full page post back.

Using a timer to move between Views in a MultiView control

I'm trying to get a timer to move between 3 Views in a MultiView control here is the code I'm using:
Protected Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim activeView As String
activeView = MultiView1.GetActiveView().ID
If activeView = "View1" Then
MultiView1.SetActiveView(View2)
End If
If activeView = "View2" Then
MultiView1.SetActiveView(View3)
End If
If activeView = "View3" Then
MultiView1.SetActiveView(View1)
End If
End Sub
On page load I have the MultiView Control set to View1 (MultiView1.SetActiveView(View1))
The page loads correctly and the data (being pulled from an SQL server is visible. After the first tick on timer1 the second view appears again showing the correct data. Then nothing I can see the reload button on the browser going at the timer interval but I never see View3 or a return to View1
Before anyone suggests I had build the If statement as If, ElseIf, EndIf but I broke it out into separate If statements to see if that would help.
It didn't.
I Hope someone can help
Cheers
Have you tried to debug your code with breaks, try to put a break in the If...End If blocks and watch if it is reachable.
You may be having different IDs set for your views, or maybe some cASE mismatching. I will suggest, rather comparing view's ID string, it is safe to compare views index by MultiView1.ActiveViewIndex, this will return only an integer which is lot safer to compare.
Hope it will work.
Sometimes I wonder if I should be let out without a carer.
I found out why the views or label.text changes weren't progressing. I had set the startup info in page_load so even though the timer was firing it was doing a page_load which was defaulting back to the original data.
Sorry for the waste of your time.
I'm off to slowly bang my head against the wall until it doesn't hurt anymore then return to my project.

I have a boolean that is not setting properly. What is causing this?

I have the following code in an Asp.Net user control:
Me.pnlAddComment.Visible = MyBase.Associate.IsAgent()
Me.lblRating.Visible = Me.pnlAddComment.Visible
Me.Rating1.Visible = Me.pnlAddComment.Visible
Now when I run this code, the value of MyBase.Associate.IsAgent() is true. Yet at no point is Me.pnlAddComment.Visible evaluating to true. When I output the results as Response.Write statements, it shows IsAgent = True, pnlAddComment.Visible = False. When I run it in debug mode, placing the line break on the second line above to allow the set to occur: I put the mouse over IsAgent and it displays "True"; I put the mouse over pnlAddComment.Visible and it displays "False".
A Co-worker suggested that it's possible that it's Panel.Visible black box code in the getter that allows the assignment to occur but returns false because some parent object is set (at that point in the code execution) to False. I've reviewed the parent objects and at no time do any of them appear to be set to not visible.
If this were a reference type I might be convinced that some other process is modifying the reference between this assignment and when it is actually used (at Render), but this is happening right at this line of code.
What would cause this boolean assignment to behave this way without throwing an exception?
Solution:
The answer turned out to be a parent object in the control hierarchy located outside of the user control itself. Since nothing was explicitly set to false, and I agreed with #Shadow Wizard, #Damien_The_Unbeliever and #CodeMonkey1 that it had to be some outside control influencing the panel at that point, I decided to put a recursive while loop to test the parent of each user control in the hierarchy at that point:
Dim o as Object = Me.pnlAddComment.Parent
While o IsNot Nothing
Me.lblMessage.Text &= "<br />" & o.ID & ": " & o.Visible.ToString()
o = o.Parent
End While
Then I just ran this on the server and the output came back with the full visibility of each control in the chain. What ended up occurring is that this control was contained within a view control within a MultiView. This view control is expected to be visible as it is supposed to be the ActiveView for this particular call, but at the point in the life cycle when my code is run, the view has not been identified as the active view. Since it's not officially active, the view is implicitly false, and all child controls return a value of false when Visible is queried.
The rest of the assignments behave as expected from that point. The lblRating control is set to false (permanently) because at that moment the proper visibility setting for pnlAddComment is false. The lesson I've learned here is not to make control visibilities dependent on each other in this fashion when there is an alternative (and just as simple) method.
The Visible getter will return false if any of the control's ancestors are not visible.
is the panel that you are using also defining the Visible propery ? it maybe shadowing the Visible property from the base class , meaning the panel has 2 properties. one on the parent and one on the child having different values. i.e.
myPanel.Visible = False
myPanel.Base.Visible = True
Check it it has any parent control which is hidden, by pasting some code will make the things more clear. It might be an issue of inheriting parent property... But I am not sure.. until and unless , code is there

Execute function on specific key stroke in VB

I'm developing a web application that displays items from a work queue to a user. When an item is selected I have the app lock that item out so no other user can select it. By hitting the back button in the app it unlocks the item.
I want to be able to unlock the item if the user hits the backspace key. I know what code I need to unlock it. I just need to know how to make the code execute on backspace key stroke.
The code that I need to execute will be server side code.
Thanks in advance.
<script>
document.onkeydown = function (e)
{
if (window.event && window.event.keyCode == 8) {
__doPostBack('__Page', 'MyCustomArgument');
}
}
</script>
If you need to execute code on server, you have to change your question accordingly
EDIT:
You could set a Hiddenfield's value to f.e. "unlockItem" and do a document.forms[0].submit() and checkthe hidden-value on serverside or better:
Use the clientside __doPostBack function generated from ASP.Net to submit page(for example on selectedIndexChanged of a DropDownList). You could even generate it from Codebehind if you want the cleanest way.
I changed the above code, but i think your next question could be how you should know which item was selected, won't it?
Then you have to clarify what items we are talking about.
On serverside you get the passed arguments with:
If Page.IsPostBack Then
Dim eventArg As String = Request("__EVENTARGUMENT")
End If
End If

How do you access a dynamically built select box's selected value with jQuery?

Is there a way to get the selected value (or text, or index) of a select box that the server fills (using ASP.NET) in the client? I've tried $("#ID").val() - but the only time that works is when I continue to another page and then go back. Even then, the value that is returned is the previously selected value - if the user changes the selection, it's not registered unless they leave the page and go back. Go easy on me, I'm new at this...
Update: Tried using a regular html select, same issue (just with a populated entry). Let me elaborate on what I'm trying to do: in a separate page, I'm getting results for an autocomplete search box. The select boxes are for filters. Naturally, if the user selects a filter, I don't want to suggest items that are no longer valid. I'm looking for the keys in the ProcessRequest method of the page that contains autocomplete info.
public override void ProcessRequest(HttpContext context)
{
string respString;
string qsKey = "q";
Customer searchCust = Session[Data.Selected_Customer] as Customer;
Dictionary<string, string> qsDict = context.Request.QueryString.ToDictionary(qsKey);
Shouldn't I get the results (for instance '&ID=foo' on the last line # context.Request.QueryString?
If you want the actual selected item itself:
$("#ID option:selected");
are you sure that 'ID' is really the id of the select box ? been awhile since i used asp.net but i remember it mucked with identifiers a lot
I use the code (below) to manipulate an ASP.NET generated select box. Within the code I obtain the value of the original select box (item). Also consider using the .text() function.
var setValue = function(item){
//if value isn't already selected, postback
if(input.value != item.text())
if(select.attr('onchange'))
eval(select[0].attributes['onchange'].nodeValue);
//set input box value
$(input).val(item.text());
$(input).removeClass('empty');
//select original ASP.NET select value (hidden)
select.val(item.text());
$(lookup).hide();
//show type if present
$('.selectType').show();
};
Hope this helps.

Resources