VB对特定记录打开的窗体窗体、VB

2023-09-08 11:12:23 作者:孤风

我使用的Microsoft Access,我想打开窗体到特定的ID被点击一个按钮时。我可以指定Do.open形式命令ID。低于code打开一个形式,但随后将会打开一个对话框,要求输入ID。任何人任何想法?

 私人小组button1_Enter()
昏暗的recordId作为整数
的recordId = Me.CurrentRecord
DoCmd.OpenFormForm3,ID =的recordId
完子
 

解决方案

首先,更改:

 的recordId = Me.CurrentRecord
 

要:

 的recordId = Me.ID
 
关于VB窗体的问题

在哪里Me.ID是当前窗体上的字段或控件的名称(Microsoft访问 - 获取记录ID,当点击按钮)

当你引用变量,把它放在引号外:

  DoCmd.OpenFormForm3,ID =&放大器;的recordId
 

这将是罚款,一个ID,这就是数字,但它会得到一个更复杂一点的文字和日期,因为你需要分隔符。这将很好地工作,只要 sometextvar 不包含引号:

  DoCmd.OpenFormForm3,Atext ='&放大器; sometextvar和放大器; '
 

否则

  DoCmd.OpenFormForm3,Atext ='&放大器;更换(sometextvar,',')及'
 

和日期采取#

  DoCmd.OpenFormForm3,A日期=#&放大器; somedatevar和放大器; #
 

要避免出现语言环境,它几乎总是最好格式化为年,月,日,因此:

  DoCmd.OpenFormForm3,A日期=#&放大器;格式(somedatevar,YYYY / MM / DD)及#
 

I am using Microsoft access and i want to open a form to a specific id when a button is clicked. Can i specify the id in the Do.open form command. the code below opens a form but then a dialog box opens asking to enter the id . anyone any ideas ?

Private Sub button1_Enter()
Dim recordID As Integer
recordID = Me.CurrentRecord
DoCmd.OpenForm "Form3", , , "ID = recordID"
End sub

解决方案

First, change:

recordID = Me.CurrentRecord

To:

recordID = Me.ID

Where Me.ID is the name of a field or control on the current form ( Microsoft Access - get record id when button is clicked ).

When you refer to a variable, put it outside the quotes:

DoCmd.OpenForm "Form3", , , "ID = " & recordID

This is going to be fine for an ID, which is numeric, but it will get a little more complicated with text and dates, because you will need delimiters. This will work well as long as sometextvar does not contain a quote:

DoCmd.OpenForm "Form3", , , "Atext = '" & sometextvar & "'"

Otherwise

DoCmd.OpenForm "Form3", , , "Atext = '" & Replace(sometextvar,"'","''") & "'"

And dates take #

DoCmd.OpenForm "Form3", , , "ADate = #" & somedatevar & "#"

To avoid problems with locales, it is nearly always best to format to year, month, day, so:

DoCmd.OpenForm "Form3", , , "ADate = #" & Format(somedatevar,"yyyy/mm/dd") & "#"