I have a form in ms access I want to filter between two dates updated on the click of a button. The field I want to filter is called Date
The dates to be filtered by are entered though a couple of a textboxs in short date format called TxtDtStrt and TxtDtEnd
the button is called NCRDateFilter
Using the NCRDateFilter button event procedure 'On Click' and the below code I would expect the form the be filtered by date range between TxtDtStrt and TxtDtEnd values
Private Sub NCRDateFilter_Click()
DoCmd.ApplyFilter "", "[Date] Between [TxtDtStrt] And [TxtDtEnd]", ""
End Sub
But it doesn't use the TxtDtStrt/TxtDtEnd values, instead shows popups asking for the TxtDtStrt and then another for the TxtDtEnd value....
Try with static values (see Docs example):
DoCmd.ApplyFilter , "[Date] Between #" & Format([TxtDtStrt], "yyyy\/mm\/dd") & "# And #" & Format([TxtDtEnd], "yyyy\/mm\/dd") & "#"
I'm currently building a solution using VBA to copy my existing query (API query) and change its parameters depending on the values in columns from the original query.
I'm using the p1 variable that contains a looped column values to be used in API URL
The result should be a multiple sheets with one query each, vba code should loop through a certain column in my first query and then pass this values into each new query.
I encountered a problem. I don't know if its regional formatting issue or not, but i cannot really paste the query into Queries.Add method. I was pretty sure i formatted the "" correctly but:
AS you can see editor flashed this part of code in red (in Notepadd++ with VBA formatting its fine)
Here is my code:
mFormula =
"let" & Chr(13) & "" & Chr(10) & " Source = Json.Document(Web.Contents(""https://rejestr.io/api/v1/krs/"" & p1 & ""/relations"", [Headers=[Authorization=""xxxxxxx""]]))," & Chr(13) & "" & Chr(10) &" #""Converted to Table"" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error), " & Chr(13) & "" & Chr(10) & " #""Expanded Column1"" = Table.ExpandRecordColumn(#""Con" & _
"verted to Table"", ""Column1"", {""address"", ""business_insert_date"", ""ceo"", ""current_relations_count"", ""data_fetched_at"", ""first_entry_date"", ""historical_relations_count"", ""id"", ""is_opp"", ""is_removed"", ""krs"", ""last_entry_date"", ""last_entry_no"", ""last_state_entry_date"", ""last_state_entry_no"", ""legal_form"", ""name"", ""name_short"", ""nip"", ""regon"", ""type"", ""w_likwidacji"", ""w_upadlo" & _
"sci"", ""w_zawieszeniu"", ""relations"", ""birthday"", ""first_name"", ""krs_person_id"", ""last_name"", ""organizations_count"", ""second_names"", ""sex""}, {""Column1.address"", ""Column1.business_insert_date"", ""Column1.ceo"", ""Column1.current_relations_count"", ""Column1.data_fetched_at"", ""Column1.first_entry_date"", ""Column1.historical_relations_count"", ""Column1.id"", ""Column1.is_opp"", ""Column1.is_rem" & _
"oved"", ""Column1.krs"", ""Column1.last_entry_date"", ""Column1.last_entry_no"", ""Column1.last_state_entry_date"", ""Column1.last_state_entry_no"", ""Column1.legal_form"", ""Column1.name"", ""Column1.name_short"", ""Column1.nip"", ""Column1.regon"", ""Column1.type"", ""Column1.w_likwidacji"", ""Column1.w_upadlosci"", ""Column1.w_zawieszeniu"", ""Column1.relations"", ""Column1.birthday"", ""Column1.first_name"", ""Column1.krs_person_id"", ""Column1.last_name"", ""Column1.organizations_count"", ""Column1.second_names"", ""Column1.sex""})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Renamed Columns3"""
Also, is it entirely possible to dynamically pass multiple variables from first query to create multiple queries to API service? Maybe someone already did something similar?
Many thanks
Alex
You need a line continuation marker (_) in the mFormula = line:
mFormula = _
I am new to access VBA.
I am trying to add 1 to all numbers in a field that are equal or greater than the value in text box [TP_Bld_OrderNum_Txt].
This is my code:
CurrentDb.Execute "UPDATE TP_Matrix " & _
"SET TP_Matrix.Order_" & Me.TP_Bld_TP_Cbo & " = TP_Matrix.Order_" & Me.TP_Bld_TP_Cbo & "+1 " & _
"WHERE TP_Matrix.Order_" & Me.TP_Bld_TP_Cbo & ">= Me.TP_Bld_OrderNum_Txt"
I get this error:
too few parameters expected 1
I believe it relates to the text box value.
If I replace Me.TP_Bld_OrderNum_Txt with a number, the query works fine.
I have the text box set up as a number.
Why doesn't it recognize its value?
You provided Me.TP_Bld_OrderNum_Txt as a literal (as a fixed string) and not its value:
& ">= Me.TP_Bld_OrderNum_Txt"
Try this instead:
& " >= " & Me.TP_Bld_OrderNum_Txt.Value
Also, it is a good practice to use .Value to explicitely use the value of the control.
I'm trying to output reports. They all follow the same information, just for different managers. I can't seem to get any of the right syntax in to modify the necessary parts (Recordsource, Caption, and 1 field that will contain a set string). I don't know what its asking me and I can get the code to find the next manager name (a recordsource) and cycle through them. I can get the code to output to PDF file no problem. It's the relevant code below that I need to figure out. It's probably completely wrong. I haven't really dealt with reports yet.
DoCmd.OpenReport "rptUsageReportTemplate", acViewReport
Reports("rptUsageReportTemplate").RecordSource = MngrUsgRptStr
Reports("rptUsageReportTemplate").Caption = MngrName & "'s " & Mnth & " Usage Report"
Reports("rptUsageReportTemplate").Controls("fldManagerHeader") = MngrName & "'s " & Mnth & " Usage Report"
Reports("rptUsageReportTemplate").Requery
DoCmd.Close acReport, "rptUsageReportTemplate", acSaveYes
The "docmd.openreport" Is in there because i couldn't stop getting the error 2451 - The report name [...] you entered is misspelled or refers to a report that isn't open or doesn't exist." I know it exists and I know it's spelled correctly. So it must be an open thing. If I can get Access to output reports behind the scenes without needing to see the report open and close, that would be great.
In short what I want is for the Report I saved to be a template and just update the values a bunch of times and save it to file.
Assuming that you have a "Managers" Table or similar (tblManagersOrSuch) the following untested sub should get you going...
Sub DoManagersReport(Mnth As Integer)
Dim rsManagers As DAO.Recordset
Set rsManagers = CurrentDb.OpenRecordset("tblManagersOrSuch")
If Not rsManagers.EOF Then
rsManagers.MoveFirst
Do Until rsManagers.EOF
DoCmd.OpenReport "rptUsageReportTemplate", acViewPreview, , , acHidden
Reports("rptUsageReportTemplate").Caption = rsManagers!ManagerID & "'s " & Mnth & " Usage Report"
Reports("rptUsageReportTemplate").Controls("fldManagerHeader") = rsManagers!ManagerID & "'s " & Mnth & " Usage Report"
Reports("rptUsageReportTemplate").RecordSource = "Select * from MngrUsgRptStr Where ManagerID = " & rsManagers!ManagerID
DoEvents
Reports("rptUsageReportTemplate").Visible = True
DoCmd.OutputTo acOutputReport, "rptUsageReportTemplate", acFormatPDF, "C:\" & rsManagers!ManagerID & " " & Mnth & " Usage Report.pdf"
DoEvents
DoCmd.Close acReport, "rptUsageReportTemplate"
Loop
End If
'add error handling
End Sub
Note that setting the RecordSource forces a requery so you do not require that.
I would also suggest adding a fileSaveAs function to determine the save folder...
I want to create a report with date as a criterium.
I have a TextBox (unbound) named ber-datum and i want to select every entry in my table thats matches with the date.
I created a button with the following code behind it.
Private Sub ber_datum_button_Click()
DoCmd.OpenReport "ber-planung", acViewReport, , "[Datum]='" & Me.[ber-datum] & "'"
End Sub
But im always getting the "Data type mismatch" error.
The data type of Datum in my table is set to Date.
Every other report works fine except this one.
Example:
Private Sub ber_hid_button_Click()
DoCmd.OpenReport "ber-planung", acViewReport, , "[HID]='" & Me.[ber-hid] & "'"
End Sub
Date expressions must be wrappen in octothorpes:
Private Sub ber_datum_button_Click()
DoCmd.OpenReport "ber-planung", acViewReport, , "[Datum]=#" & Format(Me![ber-datum].Value, "yyyy\/mm\/dd") & "#"
End Sub