VB对特定记录打开的窗体 [英] VB open form on a specific record

查看:146
本文介绍了VB对特定记录打开的窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

解决方案

首先,更改:

 的recordId = Me.CurrentRecord
 

要:

 的recordId = Me.ID
 

在哪里Me.ID是当前窗体上的字段或控件的名称(<一href="http://stackoverflow.com/questions/13497950/microsoft-access-get-record-id-when-button-is-clicked/13498362#13498362">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") & "#"

这篇关于VB对特定记录打开的窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆