Problems Searching in Access - ms-access

Wonder if any of y'all can help me. I keep getting errors on this. Here's my table:
- tblCutting
- PartNumber (Primary Key Text Field)
- CuttingStep1 (Number)
- CuttingStep2 (Number)
- CuttingStep3 (Number)
I'm trying to use a combo box (cmbPartNumber1) to pick from PartNumber and then a text box fills in with the corresponding CuttingStep1. Here's are the various formulas I've tried underneath the textbox:
=DLookUp("CuttingStep1","tblCutting","cmbPartNumber1=" & [tblCutting]![PartNumber])
=DLookUp("CuttingStep1","tblCutting","[cmbPartNumber1]=" & [tblCutting]![PartNumber])
=DLookUp("CuttingStep1","tblCutting","cmbPartNumber1=" & [PartNumber])
=DLookUp("CuttingStep1","tblCutting","[tblCutting]![PartNumber]=" & [cmbPartNumber1])
=DLookUp("CuttingStep1","tblCutting","[PartNumber]=" & [cmbPartNumber1])
None of these have worked and I have no idea why. Any suggestions?
Or am I way off on how this is supposed to work?
Edit: added field types above.

Text values need to be delimited:
=DLookUp("CuttingStep1","tblCutting","PartNumber='" & [cmbPartNumber1] & "'")
Also, since your textboxes are using a calculated formula, they are "Unbound", therefore you need to update their contents yourself.
To handle this you'll need an event sub for the "Change" event of your ComboBox. Add the following code or similar, since I do not know the names of your Textboxes. Add to your Form Module:
Private Sub cmbPartNumber1_Change()
' Refresh (recalculate) values. textBox1,2,3 are names of your Textboxes that contain calculated values based on value of cmbPartNumber1.
textBox1.Refresh
textBox2.Refresh
TextBox3.Refresh
End Sub

Related

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.

Opening form from combo box in another form

I have a form called DisplayForm. In that form is a combo box drop down that is at the top of column on the form where a label would usually go. I want to select an item from that drop down menu and use that bit of data to open another form. I have copied an example from the web, changed the names and can't get it to work. Here is the code;
If Not Me.NewRecord Then
DoCmd.OpenForm "AreaForm", _
WhereCondition:="LArea=" & Me.AreaCBDrop
End If
Area is the name of the field in the query that is the recordsource for the form, but when I run it, it opens a msgbox that wants me to enter a peramater value. I also don't understand what the IF is about. I have tried this with and without the if but get the same result. Me.AreaCBDrop has the correct value in it, but the where does not work.
Thanks
Thanks
Your WHERE condition is expecting a text parameter, but you are not supplying the expected format, so it is asking for one.
Surround your Me.AreaCBDrop with single quotes, like this:
If Not Me.NewRecord Then
DoCmd.OpenForm "AreaForm", _
WhereCondition:="LArea='" & Me.AreaCBDrop & "'"
End If

Update Display for Combo Box

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!

Access Dynamic IIF reference on form

I cant seem to figure out how to reference a combo box value on a form in another textboxs sum iif function. The sample of what I am trying to do is below, with the reference to "TestCombo" the value I want to change based on who is selected. I tried using CHR(34) quotes, and I cant seem to figure it out.
SUM(iif([SaleStatus]= 'Pending' And [SalesAdvisor] = [TestCombo],1,0))
This same function works if I do the following
SUM(iif[SaleStatus]= 'Pending' And [SalesAdvisor] = 'TestAdvisor',1,0))
That led me to believe I needed quotes, which I expected, but that doesn't work either, such as the example below.
SUM(iif"[SalesStauts]= 'Pending' And [SalesAdvisor] = " & chr(39) & [TestCombo] & chr(39) & "",1,0))
Can somebody help me use the combo box as a dynamic reference to the sum iif?
Are you sure that your combo is equal to 'TestAdvisor'? It is quite common to have a numeric bound column and a text display. If you have more than one column in the combo, you will need to refer to the column property to get the text column. If you include the RecordSource for the combo in your question, it will be easy to see.

cascading combo box causing empty fields in next record

I'm having problems with a cascading combo box. Everything works fine with the combo boxes and the values get populated correctly.
Private Sub cmbAdjComp_AfterUpdate()
Me.cboAdjOff.RowSource = "SELECT AdjusterCompanyOffice.ID,
AdjusterCompanyOffice.Address1,
AdjusterCompanyOffice.Address2,
AdjusterCompanyOffice.Address3,
AdjusterCompanyOffice.Address4,
AdjusterCompanyOffice.Address5 FROM" & _
" AdjusterCompanyOffice WHERE
AdjusterCompanyOffice.AdjCompID = " & Me.cmbAdjComp.Column(1) & _
" ORDER BY AdjusterCompanyOffice.Address1"
Me.cboAdjOff = Me.cboAdjOff.ItemData(0)
End Sub
The secondary combo box has a row source query:
SELECT AdjusterCompanyOffice.ID, AdjusterCompanyOffice.Address1,
AdjusterCompanyOffice.Address2, AdjusterCompanyOffice.Address3,
AdjusterCompanyOffice.Address4, AdjusterCompanyOffice.Address5 FROM
AdjusterCompanyOffice ORDER BY AdjusterCompanyOffice.Address1;
Both comboboxes have the same controlsource.
Everything works fine and dandy moving between records and the boxes show the correct fields for each record.
When i use the first combo box, and then select the appropriate option in the second combo box, everything works great on the specific record.
However when I move to the next record, the values in the second combo box are all empty. If i close the form and reopen it, and avoid using the cascading combo boxes all the values are all correct when i move between records.
Somehow using the cascading combo boxes creates a conflict with the row source of the secondary combo box.
Hope that is clear! Have been rummaging around for an answer but cant find anything.
any help would be greatly appreciated.
Thanks
Noel
The reason why the combo box is blank when you navigate to the next record is because you have NotInList set to TRUE (which is what you want), but when you arrive on the record, the rowsource has been filtered to not include the value stored in the field the combo box is bound to. Thus, it's blank -- the value is there, but it can't be displayed, since it's not in the list.
To fix this, you need to clear the filter on the second combo box. To do that, in the OnCurrent event of your form, set the rowsource of the filtered combo box to be unfiltered:
Me!cboAdjOff.RowSource = "SELECT AdjusterCompanyOffice.ID, AdjusterCompanyOffice.Address1, AdjusterCompanyOffice.Address2, AdjusterCompanyOffice.Address3, AdjusterCompanyOffice.Address4, AdjusterCompanyOffice.Address5 FROM AdjusterCompanyOffice ORDER BY AdjusterCompanyOffice.Address1"
I usually handle this by creating two constants at the top of the form's module, one for the SELECT statement and one for the ORDER BY:
cstrRecordsourceSelect = "SELECT AdjusterCompanyOffice.ID, AdjusterCompanyOffice.Address1, AdjusterCompanyOffice.Address2, AdjusterCompanyOffice.Address3, AdjusterCompanyOffice.Address4, AdjusterCompanyOffice.Address5 FROM AdjusterCompanyOffice"
cstrRecordsourceOrderBy = "ORDER BY AdjusterCompanyOffice.Address1"
Then it's much easier to handle. In the OnCurrent it looks like this:
Me!cboAdjOff.RowSource = cstrRecordsourceSelect & " " & cstrRecordsourceSelect
...and in the AfterUpdate of your first combo box:
Me!cboAdjOff.RowSource = cstrRecordsourceSelect & _
"WHERE AdjusterCompanyOffice.AdjCompID = " & Me!cmbAdjComp.Column(1) & _
" " & cstrRecordsourceSelect
This makes the code easier to read, and it also makes it easier to alter the rowsource if you need to, since you have to edit only the constant.