ACCESS form expression builder - ms-access

I am trying to display a record from a table after the user enters the input. I have several tables but the one from which I am trying to take the data is called Tocki. Till now I came up with this expxression:
=DLookUp("[Tocki]![Y]"," [Tocki]![X]"," [Tocki]![H]";" [Tocki]![Broj]="&[Text3])
I want to display the columns Y, X and H from the table Tocki. My text field is called Text3 and I want to search the table through the column Broj.

Did you mean a textbox is named Text3?
Cannot pull 3 separate fields with DLookup, you can pull a concatenation of those three fields. If Broj is a text type field, filter parameter needs apostrophe delimiters.
=DLookUp("[Y] & ':' & [X] & ':' & [H]", "Tocki", "[Broj]='" & [Text3] & "'")
However, DLookup can be slow performer. Better approaches usually:
include lookup table in the form RecordSource, bind textboxes and set them Locked Yes and TabStop No
multi-column combobox, then textboxes can reference the combobox columns by index

Related

Linking a query criteria to a value in a local table

I have a 5 column table with thousands of rows that I need to be able to filter. In the form where the table is displayed, Form1, I have a text field, Value1, where the table will only display the rows where Column 0 = Value1. If Value1 is blank, all rows will be displayed.
The code below is what is being currently used in the criteria and or field of my query builder and works great:
Like [Forms]![Form1]![Value1] & "*"
IsNull([Forms]![Form1]![Value1])
My goal is to have the criteria grab the value from a table, rather than a form. I created a form that pops up before Form1 that allows you to insert Value1 then hit Search. The value then goes into [Table1]![Value1] then opens Form1 and displays the filtered results. I am successfully inputting Value1 into Table1 but can't seems to get the query to react to [Table1]![Vale1]. I have tried a few different codes, the code below is an example of one:
Like [Tables]![Table1]![Value1] & "*"
IsNull([Tables]![Table1]![Value1])
Any suggestions?
You could use the DLookup function to get the value from the table, like this:
Dlookup("Value1","Table1")
This will work fine if you have only one value in the table. If you have multiple values in the table and need to have a specific value, you need to add a filter in the third parameter of the Dlookup function.
Dlookup("Value1","Table1","TableFieldName=" & [Value])
or, if the criteria value is a string
Dlookup("Value1","Table1","TableFieldName='" & [Value] & "'")
or, if the criteria value is a date
Dlookup("Value1","Table1","TableFieldName=#" & [Value] & "#")
See the docs also at : https://learn.microsoft.com/en-us/office/vba/api/access.application.dlookup

SQL Select Statement Column Selection Based on Checkbox TickMark Access

I would like to select specific columns based on the user checkbox selection.
I can able to achieve it using VBA but is it possible to arrive the fields in SQL itself based on forms checkbox tick status?
Two ideas:
1) create a text box that collects the values of the checkboxes:
= if(checkbox1,"Col1, ","") & if(checkbox2,"Col2, ","") & ...
Create a second one that removes the tailing comma.
Use the content of this second text box to build your SQL string.
2) Solution 1 requires you to hard code the columns in one formula. A more generic way would be to populate a list with the column names of your data source (the table). The changed event of the list would then generate the list of column names for your SQL string.
This solution involves VBA, yes but it's interactive. Guess that's what you're after.

MS Access convert short time in form to decimal time in table

I have an Access database with a form that contains a "ProcessTime" field, with the format hh:nn and the input mask 00:00. I've got that part working fine. In the Control Source on the associated table, however, I would like the ProcessTime field/column to appear as decimal minutes. I haven't been able to figure out how to do that.
For example, a user might enter a ProcessTime in the form as 01:30, meaning 1 hour and 30 minutes. I would like the associated value in the table to then appear as 1.5, meaning 1 and a half hours.
How can I go about modifying the ProcessTime field in the table to show the time in decimal hours? I had assumed there would be some simple "decimal time" format I could enter for the ProcessTime field in Design View, but I haven't found one yet.
I'm using MS Access 2013.
There is no intrinsic format or conversion function for this. Don't modify the field. Do a calculation in query or textbox.
[ProcessTime] is a date/time type? The following expression will work for date/time or text type.
Hour([ProcessTime]) + Minute([ProcessTime])/60
If the textbox is bound to the field, it will be problematic to make a conversion like that as you will have different data types (date/time and decimal). If it is not a bound textbox you can split the textbox value on the colon (:) and then concatenate hours & (minutes/60) and then write the information to the table.
Dim temp as string
temp = split(ProcessTime.Value,":")
currentDB.Execute "Update <table name> SET ProcessTime=" & temp(0) & temp(1)/60 & "WHERE <condition>;"
'Or you are adding a new record you can do an Insert Query
' Replace the Update statement above with "INSERT INTO <table name> (<other fields>,ProcessTime) VALUES (<other values>," & temp(0) & temp(1)/60 & ");"

MS access2013 datasheet shows display values, but listbox only shows ID

I have a table named "customers", and a table named "cases". These relate to real estate transactions. On the table "cases" I have a field for "other party", which lets you enter a new customer or pick from an existing one if we have already had that person in our database from a different transaction.
I have created a form with a listbox so I can search all the case records via the customer and other party fields (I also show some other info about the case but am not needing to search that info). In formview the listbox shows the customer name, but only shows the ID number for the other party. When I go to the rowsource, buildevent, and see the query in datasheet view, the records display the way I want them to -by name, not showing ID numbers.
Why won't it display correctly on the listbox??? Please help! I have spent way to many hours trying to figure this out :( This is my first time using access and I am just figuring it out as I go.
this is the SQL from the query in the listbox rowsource:
SELECT Query3.Customers.ID, Query3.[Last Name], Query3.[First Name], Query3.[Other Party], Query3.[Property Address], Query3.[Assigned To], Query3.Lawyer FROM Query3;
and this is the SQL from Query3:
PARAMETERS [ [forms]]![FRM_SearchMulti]![SrchText] Text ( 255 );
SELECT CasesALL.*
FROM CasesALL
WHERE (((CasesALL.[Last Name]) Like "*" & [forms]![FRM_SearchMulti]![SrchText] & "*")) OR (((CasesALL.[First Name]) Like "*" & [forms]![FRM_SearchMulti]![SrchText] & "*")) OR (((CasesALL.[Other Party]) Like "*" & [forms]![FRM_SearchMulti]![SrchText] & "*"));
Listboxes and combo boxes have a hidden column feature, usually a primary/foreign key of underlying table. Users generally do not know which primary key they should pick, hence the connecting name/item displays for their selection. Your situation sounds like the key is not being hidden but displaying and with two columns designated, you do not see the Other Party field.
To fix, under Property Sheet / Format Tab of the listbox, adjust Column Count and corresponding Column Widths according to your query (i.e., recordsource of listbox). As shown below the first column of query is hidden with 0 inches of display while the next two fields will display at 2 inches:
Column Count: 3
Column Widths: 0"; 2"; 2"
...
List Width: 4"
Be sure column widths add up to your List Width or there will be cut-offs. Also, inches are automatically added when you enter numbers. Finally, do note the data value of the listbox will be whatever is designated in Bound Column under Property Sheet / Data tab:
Bound Column: 1
Usually, the bound column is the hidden field or it wouldn't be hidden or used!
You probably miss to set columnwidth(s) of the listbox to: 0

Filtering A Lookup Field Based On Another Field

I have a lookup field in my table based on another table. I'm having trouble filtering those values based on another field that is entered prior to the field.
Is it possible to filter a lookup field based on another field?
EDIT
Let me try and clarify my original question, sorry about that. Ok, so I have a table1 that has the following fields: ID, Name, Logo.
If a user enters a specific name in the Name field, when they click on the Logo field, it'll only display those values associated that are similar to the name entered. Does that make any sense? If it does make sense, would there be an easier suggesion on accomplishing this task?
If you're talking about inside a table, the answer is "No". You can create cascading combo boxes on a form, but you can't base a lookup value in a field of a table off of a different field in that table (or the field in any other table).
Here is an example of how to handle filtering a combo box based on the value selected in another combo box:
I have the following form:
The combo boxes are named cboIntPN and cboManPN.
The Row Source for cboIntPN is set to: SELECT uniq_key, part_no, revision FROM inventor. The Row Source for cboManPN isn't set to anything.
When the user selects a value for Internal PN the following AfterUpdate Event is triggered:
Private Sub cboInternalPN_AfterUpdate()
[cboManPN].RowSourceType = "Table/Query"
[cboManPN].RowSource = "SELECT uniqmfgrhd, mfgr_pt_no FROM invtmfhd " & _
"WHERE uniq_key = '" & cboIntPN.value & "'"
End Sub
It sounds like he is having the same issue as me. I also wanted to filter a field in a table for data entry on another field's input and my conclusion is "it is time I stopped entering data manually in tables and begin to create Data entry forms. I was putting this task off until later, but if I don't do it now, I might make worse trouble for myself later.
Btw, what an old thread.