访问按钮VBA问题及子窗体的问题 [英] Access Buttons VBA Problems and Subform Issues

查看:485
本文介绍了访问按钮VBA问题及子窗体的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林工作的一个关键的库存数据库。东西来管理谁签署了房间钥匙,当他们把他们回来,我已经创建的表我计划使用,并已开始工作的形式。不过,我有麻烦的形式/子窗体工作作为期望。

Im working on a key inventory database. Something to manage who signs out room keys and when they bring them back in. I've created the tables I plan on using and have started working on the forms. However, I am having trouble getting the forms/subforms to work as desired.

我创建按钮可添加/编辑/删除/等子窗体这是表的结果的记录。我有codeD基于一个旧的项目我在我的DB类做了按钮(别人没有的形式的话,我没有查询)。我似乎无法让他们的工作。到目前为止,我只有codeD的按钮mainKeys的形式为止。

I've created buttons to add/edit/delete/etc the records in the subform which are a result of the tables. I've coded the buttons based on an old project I did in my DB class (someone else did the forms then, I did queries). I can't seem to get them working. So far, I've only coded the buttons for "mainKeys" form so far.

我发现的主要形式显示了1月14日的记录,而从我的旧项目的形式仅表现在子窗体中的所有记录。

I've noticed the main form shows 1 of 14 records whereas the forms from my old project only showed all records in the subforms.

下面是访问文件: http://jumpshare.com/b/W7AKih

下面是我的旧项目(这是我尝试复制): http://jumpshare.com/b/ r7Y6O1

Here's my old project (this is what im trying to copy): http://jumpshare.com/b/r7Y6O1

这里的$ C $下按钮:

Here's the code for the buttons:

Option Compare Database

Private Sub cmdAdd_Click()
If Me.keyID.Tag & "" = "" Then
    CurrentDb.Execute "INSERT INTO KEYS(KEY_ID, ROOM, DRAWER)" & _
        " VALUES(" & Me.keyID & ",'" & Me.roomID & "'," & Me.drawerID & ")"
          subKey.Form.Requery
Else
    CurrentDb.Execute "UPDATE KEYS " & _
    " SET KEY_ID=" & Me.keyID & _
    ", ROOM='" & Me.roomID & "'" & _
    ", DRAWER='" & Me.drawerID & "'" & _
    " WHERE KEY_ID=" & Me.keyID.Tag
End If
cmdReset_Click
subKey.Form.Requery
End Sub

Private Sub cmdBack_Click()

End Sub

Private Sub cmdDelete_Click()
If Not (Me.subKey.Form.Recordset.EOF And Me.subKey.Form.Recordset.BOF) Then
    If MsgBox("Confirm Deletion?", vbYesNo) = vbYes Then
        CurrentDb.Execute "DELETE FROM KEYS" & _
            " WHERE KEY_ID=" & Me.subKey.Form.Recordset.Fields("KEY_ID")
                Me.subKey.Form.Requery
    End If
End If
End Sub

Private Sub cmdEdit_Click()
If Not (Me.subKey.Form.Recordset.EOF And Me.subKey.Form.Recordset.BOF) Then
        With Me.subKey.Form.Recordset
            Me.keyID = .Fields("KEY_ID")
            Me.roomID = .Fields("ROOM")
            Me.drawerID = .Fields("DRAWER")
            Me.keyID.Tag = .Fields("KEY_ID")
            Me.cmdAdd.Caption = "Update Record"
            Me.cmdEdit.Enabled = False
        End With
End If
End Sub

Private Sub cmdExit_Click()
 DoCmd.Close
End Sub

Private Sub cmdReset_Click()
    Me.keyID = ""
    Me.roomID = ""
    Me.drawerID = ""

    Me.keyID.SetFocus
    Me.cmdEdit.Enabled = True
    Me.cmdAdd.Caption = "ADD KEY"
    Me.keyID.Tag = ""
End Sub

这是我所看到的重置和放大器;退出按钮工作得很好,在添加/删除/更新记录没有。 此外,这是一个小项目,我的工作在我校办公室。如果任何人有从他们在文件中看到任何建议,将是巨大的。

From what I can see the Reset & Exit buttons work just fine, the add/delete/update records do not. Also, this is a small project I am working on for an office in my school. If anyone has any recommendations from what they see in the file that would be great.

推荐答案

原因没有的情况是,在你的数据库中的事件行设置为 [嵌入的宏] 而不是 [事件过程] ,因此code您已经张贴永远不会运行。它始终是明智的,当你有问题,看看是否code到达设置断点。

The reason nothing is happening is that the event line in your database is set to [Embedded Macro] rather than [Event Procedure], so the code you have posted is never run. It is always wise to set a breakpoint when you have a problem to see if the code is reached.

在那之后,我的脑海里,你将太多的麻烦以某种方式和太少的另一个。而不是写所有的插入code当访问将要处理除了子窗体非常漂亮的,写了很多检查code,以确保数据处于良好的状态。

After that, to my mind, you are going to far too much trouble in one way and far too little in another. Instead of writing all that insert code when Access will handle an addition to the subform very nicely, write a lot more checking code to make sure the data is in good shape.

这篇关于访问按钮VBA问题及子窗体的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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