I have a combo box in a form to find a specific record;
The combo box data source is a query that has 2 fields: OB and OC ;
So far I have managed to find the record based on field OB;
But now a need to find the record using 2 criteria’s: Field OB and Field OC
Any help so I can include field OC and find the record based on two fields?
Condition where ="[OB] = " & "'" & [Screen].[ActiveControl] & "'"
Related
I cant post too much detail due to sensitive info so I will define the problem as seen below.
I have:
Table1 = read only table containing uID & other employee info
Table2 = new table created from form, using a combination of Table1 data and user input data
QueryTable1 = Query pulling relevant data from Table1 such as employees in particular department
FormA = form reading QueryTable1 to allow user to select their user id "uID"
uID = employee number and a field on Table1, Table2 and combobox on form
I am currently getting uID from QueryTable1 and populating results as options in FormA combo box. When I select a uID from the list, it pulls all data and displays to the user properly and unique to that uID. When I click Save Record it saves the FormA data to Table2. This works, however my issue is that the data populating Table1 is not the same data displayed on FormA, it is populating the same uID no matter what is selected and displayed in the FormA. The uID being populated in Table2 appears to be the lowest uID and whatever is messing up is therefore returning results based on Ascending Query.
I can't figure out how to resolve this. Selecting a control source on FormA and setting it to uID results in the value being unselectable on the combo box. Other than being unselectable, all values in the combobox appear the same as when it has no control source. Again this combo box is being populated by QueryTable1 data.
Here is my code sending data from FormA to Table2:
Dim strInsert As String
strInsert = "INSERT INTO [TABLE2] (uID, a, b, c) VALUES(" & Me.uID & ", " & Me.a & ", " & Me.b & " , " & Me.c & ")"
CurrentDb.Execute strInsert
Final example of my steps:
in FormA I select my combo box and see uID values: apple, orange, pineapple
I select pineapple, all other fields on the form populate correctly related to pineapple
I click save and the code above executes
I then refresh Table2, the value populated in uID field = apple and it should have been pineapple
Thank you for any help and I am sorry I cant post more specific info/screenshots.
I answered my own question on accident right after posting due to the code editor saying the format was wrong and showing date format which is a hidden column 0 in my combo box, and my uID is column 1. The code below resolved it, but if anyone has a better method I would appreciate your thoughts.
My combo box actually has several columns contained in it because I found that to correctly drive some of the data it populates later on the form. For this reason there are multiple columns visible and invisible in the combo box. I have a suspicion that this is not efficient. But it is working for now and thats ultimately what matters right?
Dim strInsert As String
strInsert = "INSERT INTO [TABLE2] (uID, a, b, c) VALUES(" & Me.combouID.Column(1) & ", " & Me.combouID.Column(2) & ", " & Me.combouID.Column(3) & " , " & Me.combouID.Column(4) & ")"
CurrentDb.Execute strInsert
I'm trying to build a database with MS Access. I have two tables- StockFrames and Projects, and I have a form- FrameCheckOut. On the form I have a FrameID field (where we will type in a frame id number or scan its barcode) and a ProjectName field, with a drop down of project names from the Projects table. I also have a button- Assign Frame. I want the button to update the StockFrames table with the projectID number so that I can know whether or not a frame is currently in use (or "checked out") to a project.
I have tried assigning this code to the button On Click:
UPDATE StockFrames
SET StockFrames.projectID = [SELECT Projects.projectID
FROM Projects WHERE Projects.projectName LIKE projectName]
WHERE frameID = frameID;
.. but that code contains invalid syntax. I am very new to Access and coding and I would really appreciate some help if anyone is willing.
Include key field in combobox (column can be hidden) RowSource. Value of combobox will be ID but users see and type name. Combobox properties:
RowSource: SELECT ProjectID, ProjectName FROM Projects ORDER BY ProjectName;
BoundColumn: 1
ColumnCount: 2
ColumnWidths: 0";2"
ControlSource: leave blank if control is used to enter search criteria, otherwise field you want to save into
If form is bound to StockFrames, an UPDATE action is not needed. Find record for specific FrameID and simply select project from combobox.
If you prefer to use UPDATE, then have UNBOUND comboboxes for Frames and Projects designed as described above. Example VBA:
Private Sub AssignFrame_Click()
CurrentDb.Execute "UPDATE StockFrames SET ProjectID = " & Me.cbxProject & _
" WHERE FrameID = " & Me.cbxFrame
End Sub
I've looked around for an answer to this issue, but have fond none. Thank you in advance to anyone who's able to help. I'm trying to look up records and alter them, based off multiple fields. However, my form shows up blank.
I have a database with one to many links for the following tables:
Sample->Set->Catch->Length->Diet (Key fields: SampleID, SetID, etc.)
Preliminary data is entered. I have additional data for some individuals to be entered into the Length and Diet tables. So, I created a form with combo boxes that allow the user to navigate to the correct fish by selecting: Date, Station, Set, Species, and Length. So, when I select a date, I'm restricted to stations sampled on that day and so on. I have a query string set up to restrict results to those matching the criteria entered into the combo boxes. My subform is based off the final query in this string (Query 5). It's linked on the primary key field for the length table (LengthID). All fine so far.
The issue: When I open my form and select values for each combobox, the subform remains blank. However, I can run Query 5 from the sidebar at this point and it runs successfully. I could just enter data directly into the query, but it would be less streamlined and vulnerable to human error.
I've also tried opening my subform directly from the sidebar. When I do this, Access prompts me for the Date, Station, Set, Species, and Length. Twice. The form then shows up and all are fields blank including the LengthID field, which should be filled in (since I'm looking up an existing record). I don't know why it prompts me twice, but I think that the subform isn't showing up in regular form view because the database sees the LengthID field as blank.
My combo boxes appear to navigate correctly to a given record. The query string my combo boxes and subform are based on all work when run directly. But I can't enter data into my subform, presumably because the subform can't find the correct record even though the query it's based off of can find it just fine. I've run out of troubleshooting ideas, any advice is greatly appreciated. Thanks!
If I understand correctly, you're trying to achieve a query WHERE clause utilizing combo-boxes. There are many SO questions out there on this but this should get you going. Let me know if you run into trouble and I'll help you out.
I assume you have a linked parent/subform combo. This code would be on the parent form search button:
Dim strSQL As String
strSQL = " 1=1 "
If Not IsNull(cmbComboBox1) Then
strSQL = strSQL & " AND Field1 = " & cmbComboBox1
End If
If Not IsNull(cmbComboBox2) Then
strSQL = strSQL & " AND Field2 = " & cmbComboBox2
End If
If Not IsNull(cmbComboBox3) Then
strSQL = strSQL & " AND Field3 = " & cmbComboBox3
End If
Me.Filter = strSQL
Me.FilterOn = True
I am fairly new to Access and I am having some trouble figuring out how to perform a search.
I have a table that contains records with multiple fields and one primary key field called "Serial".
I have created a form that is linked to this table and all it contains is a text box and a button where the user can type in any word or serial number and anything and the table will be searched for records that have a field that matches the criteria entered.
I have gotten to the point where I can search through the table and find any record with a match but I cannot figure out how to post this record (and any other records that match) to a newly created report so that the user can see all of the results that matched his criteria.
The code I have is as such and the output gives only a blank report.
The msgbox line always outputs the correct Serial number for every search.
I believe that the issue is related to the DoCmd.OpenReport line.
Do While Not rs.EOF 'iterate through table and check all fields
For Each Field In rs.Fields
If Field = SearchBar.Value Then
found = True
MsgBox (rs.Fields("Serial")) 'debugging
**DoCmd.OpenReport "Asset Inv", acViewReport, , "[Serial] = '" & rs.Fields("Serial") & "'"**
Exit For
End If
Next Field
If found Then
Exit Do
Else
rs.MoveNext
End If
Loop
Thanks for the help!
If you Want To search in Multiple Fields Based On one Keyword Do the Following Steps :
1- Suppose we have the following table That Want to search using a keyword in multiple fields
2- Open The Query Design And Choose You Table That You Want Search It
3 - Add Fields To The Query By Dbl Clicking On Desired Fields
4-Now Click On a Blank Column And Go To Design Tab
5-Save You Query
5-Click On Builder
6-Select Your Saved Query From The List
7-Select Fields You Want To Search in And Append Them
concatinate Fields That You Want Search in
8-Now You Have The New Column That Contained All Desired Fields
9-Now In Criteria Section Type Like ""+[]+""
10-Run The Query
Write "Like" Sql Command And Run Query
Enjoy It ...
I have almost finished a project and I would like some user options in the form.
I would like to allow the user to select a product code and when selected, it will find the relative record in the table and then display all the information from that in a report.
Any ideas on the best approach to this would help me out massively.
Use the combo box selection with DoCmd.OpenReport as the WhereCondition option.
So if the report's record source table or query includes a numeric field named product_code and your combo box is named cboProductCode ...
DoCmd.OpenReport "YourReport", _
WhereCondition:="[product_code] = " & Me.cboProductCode
If the field is text rather than numeric, add quotes around the value in the WhereCondition.
WhereCondition:="[product_code] = '" & Me.cboProductCode & "'"