动态查询标准(Dynamic Query Criteria)
我正在尝试使Microsoft Access查询依赖于另一个窗体的文本框中的值。
这是现在的标准。 基本上,2014年4月1日至2015年3月31日之间的任何日期。这很有效。
>=#2014-04-01# And <#2015-04-01#
我想要一个带有年份的文本框(使用当前示例2014),并使查询条件(2014,2014 + 1)取决于此值。
我试图拆分上面的语法,然后在标准中连接,如下:
">=#" & "2014" & "-04-01# And <#" & "2015" & "-04-01#"
我收到错误“标准表达式中的数据类型不兼容”。
1.是否可以在查询条件中连接? 我也尝试过SQL CONCAT(string1,string2,string3,..),但无济于事。 如果这是可能的,那么我想我可以使用[Forms]![Form1]。[Textbox1]和([Forms]![Form1]。[Textbox1] + 1)来替换岁月。 如果这不可能......
2.有更好的方法使查询条件动态化吗?
我尝试通过创建具有类似代码的模块来使以下解决方案工作:
Private m_varQueryParam As Variant Public Function SetQueryParam(ByVal sValue as Variant) m_varQueryParam = sValue End Function Public Function GetQueryParam() As Variant GetQueryParam = m_varQueryParam End Function Query: SELECT * FROM tblYourTable WHERE [FilterField] = GetQueryParam() The VBA Code to launch the query will look like this. SetQueryParam "your value here" DoCmd.OpenQuery "qryYourQueryHere"
但我根本不明白如何让这个工作。
编辑:我创建了一个简单的访问数据库,试图让它工作。
- Textbox1,默认值= Date()
- bSave,按钮
- tDateInfo,表:日期(日期/时间),信息(文本)以及随机日期和信息。
- 查询1:
SELECT tDateInfo.date, tDateInfo.info FROM tDateInfo WHERE (((tDateInfo.date)=GetQueryParam()));
这是表单的vba代码
Option Compare Database Private Sub bSave_Click() sValue = Me.TextBox1.Value SetQueryParam (sValue) End Sub
这是模块vba代码
Option Compare Database Option Explicit 'is this necessary? Private m_varQueryParam As Variant Public Function SetQueryParam(ByVal sValue As Variant) m_varQueryParam = sValue End Function Public Function GetQueryParam() As Variant GetQueryParam = m_varQueryParam End Function
查询条件是
GetQueryParam()
感谢您的帮助。
I'm trying to make a Microsoft Access query depend on a value in another form's textbox.
This is the criteria, as it is now. Basically, any date between April 1st 2014, and March 31st 2015. This works well.
>=#2014-04-01# And <#2015-04-01#
I'd like to have a textbox with the year (with the current example 2014), and make the query criteria (2014, 2014+1) depend on this value.
I've tried to split the above syntax, then concatenate in the criteria, as such:
">=#" & "2014" & "-04-01# And <#" & "2015" & "-04-01#"
And I get an error "Data types in the criterion expression are incompatible".
1. Is it possible to concatenate in the query criteria? I have also tried the SQL CONCAT(string1,string2,string3,..), to no avail. If this is possible, then I guess I can use [Forms]![Form1].[Textbox1] and ([Forms]![Form1].[Textbox1] + 1) to replace the years. If this is not possible...
2. Is there a better way to make the query criteria dynamic?
I tried to make the following solution work by creating a module with similar code:
Private m_varQueryParam As Variant Public Function SetQueryParam(ByVal sValue as Variant) m_varQueryParam = sValue End Function Public Function GetQueryParam() As Variant GetQueryParam = m_varQueryParam End Function Query: SELECT * FROM tblYourTable WHERE [FilterField] = GetQueryParam() The VBA Code to launch the query will look like this. SetQueryParam "your value here" DoCmd.OpenQuery "qryYourQueryHere"
But I simply do not understand how to get this to work.
EDIT: I created a simple access database, to try to get this to work.
- Textbox1, default value =Date()
- bSave, button
- tDateInfo, table: date (date/time), info (text) with random dates and info.
- Query1:
SELECT tDateInfo.date, tDateInfo.info FROM tDateInfo WHERE (((tDateInfo.date)=GetQueryParam()));
Here's the form's vba code
Option Compare Database Private Sub bSave_Click() sValue = Me.TextBox1.Value SetQueryParam (sValue) End Sub
Here's the modules vba code
Option Compare Database Option Explicit 'is this necessary? Private m_varQueryParam As Variant Public Function SetQueryParam(ByVal sValue As Variant) m_varQueryParam = sValue End Function Public Function GetQueryParam() As Variant GetQueryParam = m_varQueryParam End Function
And the query criteria is
GetQueryParam()
Thank you for your help.
原文:https://stackoverflow.com/questions/23934581
最满意答案
相关问答
更多-
您可以使用格式化功能,例如: DT::datatable(table.Drawdowns(rets)) %>% formatDate(c(1,2,3), method = 'toDateString') 得到: You can use a formatting function, for example: DT::datatable(table.Drawdowns(rets)) %>% formatDate(c(1,2,3), method = 'toDateString') Gives:
-
此功能已添加到DT (> = 0.1.3)。 例子: library(shiny) if (packageVersion('DT') < '0.1.3') devtools::install_github('rstudio/DT') library(DT) shinyApp( ui = fluidPage( fluidRow( h1('Client-side processing'), DT::dataTableOutput('x1'), h1('Server ...
-
你需要检查两个选项: 1)输入存在 2)输入> 0 喜欢 : conditionalPanel( condition ="typeof input.dt_rows_selected === 'undefined' || input.dt_rows_selected.length <= 0", DT::dataTableOutput(outputId = "dt")) , conditionalPanel( condition = "typeof input.dt_rows_ ...
-
稍微调整提供的代码,它应该产生所需的输出: createLink <- function(val) { sprintf(paste0('', substr(val, 1, 25) ,'')) } websites$url <- createLink(websites$url) HTML的工作方式如下: Linktext 因此,您 ...
-
我没有深入参与DT但这个JS回调函数有效: function(settings, json) { var table = this.DataTable(); table.on("click.dt", "tr", function() { Shiny.onInputChange("rows", table.row( this ).index()); var tabs = $(".tabbable .nav.nav-tabs li a"); $(tabs[1]).click(); ...
-
没有必要包含jquery ,而是使用options参数: scrollX :布尔值( TRUE或FALSE ) scrollY :像素数或任何其他有效的CSS单位。 码: output$tbe <- renderDataTable(mtcars, options = list(scrollX = TRUE, scrollY = "200px")) 输出: There is no need to include the jquery, instead use the options argument: sc ...
-
这应该做到这一点。 使用#mytable1 .table th我们可以访问表头。 用#mytable1 .table td我们可以访问表格单元格。 使用text-align: left; 我们将文本对齐到左边。 library(shiny) library(shinyjs) library(DT) library(ggplot2) ui <- fluidPage( title = "Examples of DataTables", ## CSS-Code ############### in ...
-
在Shiny中创建DataTable(Create DataTable in Shiny)[2022-03-17]
首先, lastOne和lastTwo应该是反应性的,例如tokens 。 但是它仍然不能在我的计算机上运行,因为在你的代码中你没有指定包含word命令的包。 First, lastOne and lastTwo should be reactive such as tokens. But then it still does not run on my computer since in your code you do not specify the package containing the wor ... -
添加radiobutton以在Shiny中选择DataTable行(Adding radiobutton to select a DataTable row in Shiny)[2023-09-15]
“脏”修复可能是将整个数据表用C id和shiny-input-radiogroup类包装在div : shinyApp( ui = fluidPage( title = 'Radio buttons in a table', tags$div(id="C",class='shiny-input-radiogroup',DT::dataTableOutput('foo')), verbatimTextOutput("test") ), server = function( ... -
嗨我认为第4步的问题是input$select_button的值没有改变,粘贴在this.id的时间似乎修复了它。 看下面的代码(我做了一些其他改动): library(shiny) library(DT) library(shinydashboard) library(shinyjs) # ----- function which create the button into the table shinyInput <- function(FUN, len, id, ...) { inputs ...