本文介绍了Microsoft Access VBA问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对在Access中编码VBA相对较新。   我想验证是谁点击了运行更新数据库的宏的按钮。  它会使用On Click事件更新名为AuditLog的表。    我要在表中更新的
数据是用户ID字段,日期字段,然后添加静态文本在该记录中称为"负余额"。     注意 - 没有表格供用户填写。 我下面的代码是一个
尝试弄清楚如何将3个字段插入表中,但是我遇到了me.modified_by和me.modified_on的问题,因为我相信"我"。将与表格有关  你能帮我指导我应该纠正什么吗? 

I'm relatively new to coding VBA in Access.    I want to verify who clicked a button which runs a macro that updates the database.   It would update a table called AuditLog with an On Click Event.    The data I want to update in the table are a user ID field, a date field and then add static text in that record called "negative balance".     Note -- there is no form for the user to fill out.  My code below is an attempt to figure out how to insert the 3 fields into the table, but I'm running into issues with the me.modified_by and me.modified_on as I believe the "me." will relate to a form   Can you help coach me on what I should correct? 

Private Sub Command505_Click()

Dim sql As String

Private Sub Command505_Click()
Dim sql As String

Me.modified_by = Environ(" USERNAME")

Me.modified_on =格式(Now()," yyyy-MM-dd hh: mm:ss")

sql ="插入AuditLog值('"& Me.modified_by&"','"& Me.modified_on&"', '"& NegativeBalance&"');" b
DoCmd.RunSQL sql

Me.modified_by = Environ("USERNAME")
Me.modified_on = Format(Now(), "yyyy-MM-dd hh:mm:ss")
sql = "Insert into AuditLog Values('" & Me.modified_by & "', '" & Me.modified_on & "', '" & NegativeBalance & "');"
DoCmd.RunSQL sql

End Sub

推荐答案

我注意到这个问题与VBA代码有关访问。为了更好地解决您的问题,我会将线程移至Access for developers论坛进行进一步的故障排除。

I notice that the issue is related to the VBA codes in Access. To better resolve your issue, I would move the thread to Access for developers forum for further troubleshooting.

感谢您的理解:)

最好的问候,$
Winnie Liang

Best Regards,
Winnie Liang


这篇关于Microsoft Access VBA问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 01:42