Update Display for Combo Box - ms-access

I have a form with multiple combo boxes, these boxes have 2 column list where column 0 width is zero. All these boxes have row sources defined for their drop down list values.
When I try to over ride the display value of the combo boxes via vb code, it works for few of the controls while doesnt do anything for the rest. So I made an isolated code just to update values of all combo boxes(cbo) and again the same controls pass/fail. Here is the code I am trying to work with, can anyone please tell me why I am unable to update some combo boxes while others work fine?
Thanks!
Sub test()
Dim Ctrl As Control
Dim CtrlName_Combined as String
For Each Ctrl In Forms("frmNewTransaction").Controls
'Name of all combo boxes start with 'cbo'
If Left(Ctrl.Name, 3) = "cbo" Then
Ctrl = "Hello"
CtrlName_Combined = ctrlName_Combined & Ctrl.Name & " "
End If
Next Ctrl
MsgBox CtrlName_Combined
End Sub
Here is screenshot of the form after code run (All Combo boxes start with cbo):

Thank you guys for the help. The problem started when few of the combo boxes did not take value when i executed:
forms("FormName").Controls("ComboBoxName")="Some Value which was in the list"
So I tested all my combos by passing them value "Hello" which I know was not in their row source. Strangely so few combos responded and others did not. This was the rabbit hole as all my combos were configured same apart from their row source queries but all had an ID and eName column.
Problem was that few combos were not taking the text values I passed them but turns out that if I gave them Numeric value according to the first column they start responding (what i dont get here is that how some combos behave one way and rest the other way)
Anyway this helped me get past the problem, thought i should share this after bothering you all with it.
Also I am seeing that the question or manner was not well received by the community, would be helpful if someone pointed out what not to do for future references
Thanks Again!

Related

Paste a value in a textbox on the second tab of a navigation form access vba

I'm quite new to VBA and I've been looking around but cannot seem to find a solution to my problem.
I have made a navigation form (frmNavigation) with 3 buttons, each referring to a different form, let's call them frm1, frm2 and frm3. In the navigationform the control buttons to switch between tabs are all named differently (btn1, btn2, btn3), but the subform that shows either frm1, frm2, or frm3 has the same name: “NavigationSubform” (this shows a different form depending on which tab is clicked on, based on the 'navagation target name' referring to frm1, frm2 and frm3).
When I want to refer to a textbox (txtBox1) on form 1 (first tab) and insert a value i can do this by:
Forms!frmNavigation!NavigationSubform.Form!txtBox1.Value = "insert awesome text"
But how would I refer to txtbox10 on the second tab (frm2)? Just using the following does not work:
Forms!frmNavigation!NavigationSubform.Form!txtBox10.Value
You then get the error 2465 (can't find the field).
I’ve been trying many different things, but can’t seem to get it right. So how do I refer to a textbox on a different tab than the first one?
Help us much appreciated!
Only one subform can be loaded at once. So you've just got to break this process into two steps.
Store the value from txtBox1 somewhere outside of the NavigationSubforms (a textbox on the parent form with visible = no, a global variable or a table works).
In frm2's On Load event, set txtbox10 to be the value you stored.
Just note, that you will need to add conditions in the On Load event if you want to avoid that textbox being set to an empty string or a wrong value if you have a setup where your filter is changing.

Referencing the value of a hyperlinked text box

So I'm having some difficulties with this code. I know it's obnoxiously wordy, but every attempt I made to turn some of these form references into variables to save space ended with me having even less functionality than before.
Basically what I've done so far is create a navigation form with several tabs, one to create a ticket, one to resolve/edit a ticket, and one to search the tickets. The search tab is basically a continuous form that updates based on the search criteria I enter. My goal is that when I click on the ticketID for each record, it will take me to the selected record on the Resolve/Edit Ticket page (on that page I have a combo box [called cboGoToRecord] where you can select the record you want).
I have a hyperlink in place that takes the user to the Resolve/Edit page and code that works ONLY when the line I've denoted with four asterisks (for clarity) is replaced with
rst.FindFirst "ticketID =" & [some number].
When I do that, the results are as expected. If I leave it as it is below, every record looks up the first record (A Debug.print check shows that the value of this field is apparently always 1...) So I guess what I need to figure out is how do I access the ticketID hyperlink's value so that I can put it on that line and make my code function effectively? I apologize if this is overly detailed but figured too much was better than not enough.
Private Sub ticketID_Click()
'Takes user from Search Tickets to Resolve/Edit Issues tab
DoCmd.BrowseTo acBrowseToForm, "frmResolveIssues", "frmBrowseTickets.NavigationSubform"
On Error Resume Next
Dim rst As Object
Set rst = Forms!frmBrowseTickets!NavigationSubform.Form.RecordsetClone
[Forms]![frmBrowseTickets]![NavigationSubform].Form![cboGoToRecord].Value = [Forms]![frmBrowseTickets]![NavigationSubform].Form![ticketID].Value
****rst.FindFirst "ticketID =" & [Forms]![frmBrowseTickets]![NavigationSubform].Form![cboGoToRecord].Value
Forms!frmBrowseTickets!NavigationSubform.Form.Bookmark = rst.Bookmark
Debug.Print [Forms]![frmBrowseTickets]![NavigationSubform].Form![ticketID].Value
End Sub
Edit:
After altering my form to add a separate hyperlink and referencing the static ticketID, I have concluded that everything I thought was true was not. Finding the value of a hyperlink was NOT the problem. The problem is that my ticketID value truly does insist on being one, and I have no clue how to fix that.
When this works:
Debug.Print [Forms]![frmBrowseTickets]![NavigationSubform].Form![ticketID].Value
then also check out:
Debug.Print [Forms]![frmBrowseTickets]![NavigationSubform].Form![cboGoToRecord].Value
As June7, I never use the Navigation form. It complicates everything too much.

Filtering form results with a combo box in microsoft access

Ok so I've been trying to look for a solution to this since I'm new to access but can't find anything (seriously no one has experienced this problem?)
Here's the problem:
I'm trying to filter the data in my CustomerSearch form by last name using a combo box which includes all the last names in my Customer table.
Using an "After Update" event macro, I use the "ApplyFilter" action and input the "Where Condition" with the following lines with different results:
(1) [LastName]=[Forms]![CustomerSearch]![cboLastNameSearch]
--> gives me blank results
(2) [LastName]=[cboLastNameSearch]
--> a popup appears every time I use the combo box asking for a last name input, which defeats the purpose of making the combo box in the first place.
where cboLastNameSearch is the name of the combo box.
Could anyone please kindly explain why (1) doesn't work, and how to improve on (2) so the popup stops showing? Thanks in advance.
Try this:
"[LastName]='" & [Forms]![CustomerSearch]![cboLastNameSearch] & "'"

Autofilling my form in Access with the use of a Combo Box

I'm having a problem when I want to autofill my form in Microsoft Access. The idea is that I use a combo box to select a name. Then the onChange code of my Combobox automaticlly inserts all the other data in the proper field. I use this code on the Combo Box.
Private Sub cmbName_Change()
Me.tbPersonalNumber = Me.cmbName.Column(0)
Me.tbEmailadress = Me.cmbName.Column(2)
Me.tbBirthday = Me.cmbName.Column(3)
End Sub
This methode works fine for the personalnumber and the emailadress. But it doesn't work for the birthday date, it returns a null value but when I check my table there is is a date in the proper field.
Am I missing something? I tried everything but it wont work.
I was thinking that the problem is related to the birthday column being the last in the table. Or having the date type.
Thank you in advance for your time and efford!
Edit; The .Column(1) is missing because this is the name that is already inserted with the ComboBox.
There is some confusion caused by the wording of the question, I'll try to state back how I've interpreted and if I have it right it may lead you to an answer.
You have combo box called cmdName that is pre-populated with data from a table. The content of the combo box could look as below (you may have set column widths to zero to hide the data)
0001|Gary Evans|gary#email.com|01/Jan/1970
0002|J Rommers |JR#email.com |02/Jan/1970
When the user selects J Rommers Me.tbPersonalNumber is populated with Me.cmbName.Column(0) (0002) and Me.tbEmailadress is populated with Me.cmbName.Column(2) (JR#email.com) but Me.tbBirthday is not being populated with Me.cmbName.Column(3) (02/Jan/1970).
Assuming Me.tbBirthday is a text box with no code that might clear it out, I suspect the issue is within the combo box. Not being sure how your combo box is set up, I would suggets the following checks:-
In the combo box properties, does the Column Count equal 4?
In debug, with a breakpoint on Me.tbBirthday = Me.cmbName.Column(3), does it show you the date you are after?
If it is not there does the query that populates the combo box have it in?
Edit based on comments to help further: -
Change the query to SELECT Personel.PersonalNumber, Personel.Emailadress, Personel.Birthday, Personel.Name FROM Personel ORDER BY Personel.Name; this puts all the fields you want hidden at the front.
Change the column widths property of cmbName to 0,0,0, this first the ones you want hidden and leave the last one to fill the width of the combo box.
Ensure the column count property is still 4 as per the answer
Change your code as per below and Gustav's answer
Replacement code:-
Me.tbPersonalNumber = Me.cmbName.Column(0)
Me.tbEmailadress = Me.cmbName.Column(1)
Me.tbBirthday = DateValue(Me.cmbName.Column(2))
This accounts for the fields moving in the query and ensure the date shows as a date like you wanted.
Comboboxes (and Listboxes) always return a string, so convert that to a Date value:
Me!tbBirthday.Value = DateValue(Me!cmbName.Column(3))

MSAccess 2010 - Subform in a subform not showing fields

I have a database with a main form, and on the main form is a subform. The subform also has a subform, which gets hidden unless a field on the first subform (the parent subform) is set to "ticket," at which time the second (child) subform appears. I got it working beautifully, except that the child subform appears blank, with no fields or labels on it. Just a background color that I set on the child subform itself.
I am using the following code in the AfterUpdate
Private Sub EventTypedd_AfterUpdate()
'Make the Ticket subform visible once EventTypedd is set to TICKET
If Me.EventTypedd.Value = "Ticket" Then
SBFCreateTicket.Visible = "True"
Else
SBFCreateTicket.Visible = "False"
End If
End Sub
Can anybody suggest possible reasons why the subform won't show the fields? The form itself shows up as it should, and the background color of the form shows up, but none of the fields or the field labels show up, and I can't figure out why. Anyone know why, or have a suggestion? Thanks!
I would like to ask a question or two but don't have the Stackoverflow kudos to do this. The issue maybe that you are not refreshing the final subform. So that when you go into the main form record without touching it, the final subform query returns zero records.
You then set flags on the top form and you should see results but the subform may not have re queried.
Try...
SBFCreateTicket.requery '<<< New line before your original code.
If Me.EventTypedd.Value = "Ticket" Then
SBFCreateTicket.Visible = "True"
Else
SBFCreateTicket.Visible = "False"
End If
Okay, I figured it out. Apparently, the AllowEdits on the second subform was set to NO, and I'm not sure why. As soon as I set it to YES, the form shows up and everything works perfectly. And as usual, as soon as I solve one problem, another one crops up a little farther down the workflow process, but that's a subject for another thread. Thanks to the ONE person that tried to help me out, anyway. :)