Get Current Price of Product - ms-access

Good Day all,
I need help with my expression. I am trying to place it in a text box in my Form. When the Product (sUPC) is selected the most recent price is automatically filled based on the current date. I have a Prices Table (Prices) that stores the current price of the product. EFFDATE is the date when the price will be applied. UPC is the ProductID on the prices table and sUPC is the combo box on my form.
DLookUp("Price","Prices","sUPC=UPC" And
Format(Now(),"dd/mm/yyyy")=DMax("[EFFDATE]","Prices",
"[EFFDATE]<=#" & Format(Now(),"dd/mm/yyyy") & "#"))
After selecting the Product the text box remains blank.

You are making it too complicated:
DLookUp("[Price]", "[Prices]", "sUPC = 'UPC' And [EFFDATE] = DMax('[EFFDATE]', '[Prices]', '[EFFDATE] <= Date()')")
For a specific date:
DLookUp("[Price]", "[Prices]", "sUPC = 'UPC' And [EFFDATE] = #" & Format(SomeOtherDateValue, "yyyy\/mm\/dd") & "#")
or a mix of these:
DLookUp("[Price]", "[Prices]", "sUPC = 'UPC' And [EFFDATE] = DMax('[EFFDATE]', '[Prices]', '[EFFDATE] <= #' & Format(SomeOtherDateValue, 'yyyy\/mm\/dd') & '#')")

DLookUp("[Price]","[Prices]","sUPC =UPC And [EFFDATE] = DMax('[EFFDATE]', '[Prices]', 'sUPC=UPC And [EFFDATE] <= #' & Format(Date(), 'dd\/mm\/yyyy') & '#')") sUPC=UPC was missing from the EFFDATE criteria –

Related

Access Dcount function with 4 criteria

I appreciate some help
I am trying to use Dcount function with 4 criteria
I have a text box in a form to count records on table_orders
The DCount function has 4 criteria:
The ID field in table_orders has to match the Form ID field
The field nature on table_orders has to be null
The field team on table_ordres has to be different than “Canceled”
The field ram (yes/no field) in table_ordes has to be “No”
I´ve been trying in many different ways with no success
This is my last try:
=DCount("*","Table_orders","ID=" & [ID]& " AND IsNull(nature)=true" & " AND [team] <> "Canceled" & AND [ram] ="No")
Try this:
=DCount("*","Table_orders","ID = " & [ID] & " AND [nature] Is Null AND [team] <> 'Canceled' AND [ram] = 'No'")

Select with 2 conditions

can you please help me to fix the following code:
The code is trying to get data according to the 2 conditions:
Select data when a checkbox and a value form a drop down list is checked
Select data when only a checkbox is checked ( this one is working fine so I am not going to list it)
If I select multiple check boxes the values are shown properly but when I try to add the second condition no values are shown.
Date looks like this DD/MM/YY
I am using vb and mysql(DB)
If c1check AndAlso ComboBox2.SelectedItem > 0 Then
searchQuery = "Select USERS_NUMBER FROM DB WHERE EXPIRATION_DATE LIKE '%" _
& String.Join("%'and EXPIRATION_DATE LIKE " + "'%", myList) _
& + "%' AND RIGHT(EXPIRATION_DATE, 3) = '%" & Trim(ComboBox2.SelectedItem.ToString) & "'"

DCount not working on Access

I don´t know whats wrong with this query... I want to know how many records are on another query named: Querie_Planilla that have the following characteristics:
The date on the field PeriodoInicial has to be greater or equal to the date [FechaInicio] but a year ago
The date on the field PeriodoFinal has to be smaller to the value [FechaInicio] (Both of this conditions consider the first day of the month in FechaInicio
It has to have the same ID im looking for: PlazaID = [Vacaciones]![PlazaID]
Here is the code:
DCount("PlazaID","Querie_Planilla","PeriodoInicial >= #" & DateSerial(DatePart("yyyy",[FechaInicio])-1,
DatePart("m",[FechaInicio]),1) & "# AND PeriodoFinal < #" & DateSerial(DatePart("yyyy",[FechaInicio]),
DatePart("m",[FechaInicio]),1) & "# AND PlazaID = '" & [Vacaciones]![PlazaID] & "'")
Right now its returning 0 but at least i have 3 for each ID

MS Access Date not working in VBA SQL query

There is a table in MS Access having 3 columns:
ID (Primary key)
Date (Date/Time)
Train no (short text)
I have designed a form where date can be selected from a combo box and according to the date selected, respective trains should be displayed.
Problem is, the query works fine on dates above 10 (like 11/1/2015) but below 10 (like 9/1/2015) it gives error : "No current record" . The record is there in the table but it doesn't display.
The query is : SELECT DISTINCT [Train No] FROM Issue WHERE [Date] = #" & dt & "#"
dt is the date selected from the combo box.
Try this:
Dim DateSelected As Date
Dim DateString As String
DateSelected = DateValue(Me!YourComboBox.Value)
DateString = Format(DateSelected, "yyyy\/mm\/dd")
SELECT DISTINCT [Train No] FROM Issue WHERE [Date] = #" & DateString & "#"

"Data type mismatch in criteria expression"

I have tried to select all records from a table from date1 to date2, Example Jun 28, 2014 to Jan 05, 2015, for display. Basically, sort out selected records based on date criteria. Big thanks if anyone could point out my mistake.
What I tried to do here is allowed user to select specific dates from calendar to view the records
I have gone through all answers, but still couldn't find similar solution to mine. I think, there may be some error in my syntax.
sqlDateRangeSearch = "Select * from BatteryDataTable where ((BatteryDateChanged) <= ""*" & Me.FromDTPicker.Value & "*"")" & " and ((BatteryDateChanged) <= " & """*" & Me.ToDTPicker.Value & "*""));"
Me.RecordSource = sqlDateRangeSearch
I noticed you have wildcard characters in the search criteria for the query. If using dates, you'll want to avoid those. Also, you don't need quotes for dates in access queries. If you're dynamically creating SQL I'd use something like:
sqlDateRangeSearch = "Select * from BatteryDataTable where (BatteryDateChanged <= #" & Me.FromDTPicker.Value & "#)" & " and (BatteryDateChanged <= #" & Me.ToDTPicker.Value & "#));"
Just a side note, your comparison operators are the same. I think you want it to say something like (remember the "#" symbols):
...WHERE (Field1 >= #Date1# AND Field1 < #Date2#);
Hope that helps!