English 中文(简体)
多文本框和查找
原标题:Multiple Text Box and Lookups

我目前正在努力改进我从我的前任工作中继承的VBA数据库。

我有一个表格,它现在只是一个大格式, 包含32个单独的文本框, 每一个后面都有相同的代码, 但每个文本框重复同样的代码, 每一个文本框的引用都在变化。

Private Sub Cand_No2_AfterUpdate()
Cand_Name2 = DLookup("[Name]", "[qryExamAbsences]", "[Cand_No] = Cand_No2")
End Sub

一旦按下按钮

If Not IsNull([Cand_Name1]) Then
 Rope = Rope & " Or Cand_No = " & [Cand_No1]
End If

(如果语句包含在按键鼠标下载事件中 。)

每个文本框的正确性为每个文本框, 然后过滤打印供办公室使用的报告。 这个问题有许多问题, 但我要解决的主要问题是,条目数量有上限, 如果我需要过滤超过32个, 我需要删除文本, 并重新开始原样 。

是否有办法将所有这些合并成一个代码的单部分,以便在需要时创建文本框?

编辑。

我找到了一种办法给用户一种印象,即文本框是在每个条目从用户角度改进了表格之后创建的(不再有32个文本框或必须滚动到打印按钮。 )然而,这仍然没有解决混乱代码的问题,因为我不得不为每个框重复额外的代码,它也留给我最多32个条目。

新法典如下:

If Not IsNull(Cand_Name1.value) Then
 Cand_No2.Visible = True
 Cand_Name2.Visible = True
 cmdPrint.Top = 2500
 cmdPrint.Left = 2500
 DoCmd.MoveSize 1440, 2201, , 4000
Else
 Cand_No2.Visible = False
 Cand_Name2.Visible = False
 cmdPrint.Top = 2000
 DoCmd.MoveSize 1440, 2201, , 3500
End If

基本上让下一个文本框可见, 并下移打印按钮为新文本框留出空间。 它还会扩展窗口 。

最佳回答

您不能只拥有两个文本框,一个为 CAND_ NO,另一个为 CAND_ NAME,然后在这两个框旁边设置 ADD CAND_ NO 按钮。

创建一个列表框, 列表框将列出每个 CAND_ NO / CAND_ NAME 在他们按下添加按钮后, 列表框将列出每个 CAND_ NO / CAND_ NAME 列表框, 以便他们可以看到他们迄今已经添加了什么 。 然后通过列表框循环以构建您的绳索, 或者在窗体上设置一个全局变量, 并在它们添加数字时构建它, 或者存储在隐藏的文本框中, 存储它们添加数字时的值, 如果您不喜欢全局化的话 。

问题回答

暂无回答




相关问题
Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

Outlook 2007 CommandBarControl.Execute won t work

I recently switched to Outlook 2007 and noticed that my VBA-macros won t work. I use the following code to open a new appointment-item (and fill it automatically). It worked perfect in Outlook 2003, ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

MS Access: list macro from VBA

I have to deal with a few macros (not VBA) in an inherited Access application. In order to document them, I would like to print or list the actions in those macros, but I am very dissatisfied by ...

热门标签