简体   繁体   English

MS Access VBA-“自定义列”为列表框(使用来自表的另一列中的值)

[英]MS Access VBA - Custom Column is ListBox (using a value from another column coming from a table)

Hello Stackoverflow community! 您好Stackoverflow社区!

My question is in reguards to creating a custom column within a list box that is pulling from a table using SQL. 我的问题是在使用SQL从表中提取的列表框中创建自定义列。 Refering to the code and picture of the current list below, I want to create a custom column that is not stored in a table, that will be called "DaysActive" and will take todays date minus the StatusEffect Date for each individual record displayed and give the number of days in its own column, say between StatusEffect and Yr. 参考下面当前列表的代码和图片,我想创建一个未存储在表中的自定义列,该列将称为“ DaysActive”,并且将采用今天的日期减去所显示的每个记录的StatusEffect日期,并给出在其自己的列中的天数,例如StatusEffect和Yr之间的天数。 Is this possible? 这可能吗? Thank you in advance for taking the time to read through this. 预先感谢您抽出宝贵的时间阅读此内容。

Private Sub Form_Load()

DoCmd.RunCommand acCmdWindowHide

Dim rs As Recordset
Dim strSQL As String
Dim lstnum



strSQL = "SELECT LastName, FirstName, Status, StatusEffect, Yr, Make, Model, VIN, Deduction, USLicense, RegistrationState, Dependents,Notes, ID FROM InsuranceTable" & _
"WHERE SentRegistration = False And Status IN ('active','add') Order By StatusEffect Desc "

Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
Set Me.lstInfo.Recordset = rs

lstnum = [lstInfo].[ListCount]
Me.lstcount.Value = lstnum - 1
End Sub

Link to picture of my current list since I do not have enough rep points to embed it ;/ 链接到我当前列表的图片,因为我没有足够的代表点来嵌入它; /

Use the DateDiff() function in your SQL. 在SQL中使用DateDiff()函数。
DateDiff('d') returns the difference in days. DateDiff('d')返回以天为单位的差额。

SELECT ..., StatusEffect, DateDiff('d',[StatusEffect],Date()) AS DaysActive, Yr, ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM