我正在尝试在我的数据库中创建一个简单的“添加记录”表单。这是添加一个新的记录集。这些数据需要在三个表格中重复/添加(尽管现在我正在努力将其添加到一个表格中!
我尝试过使用附加查询,但它不会将表单中的数据拉入附加记录中。这是我尝试追加查询:
INSERT INTO Log ( State, Jurisdiction, Company, DueDate, Preparer )
SELECT Log.State, Log.Jurisdiction, Log.Company, Log.DueDate, Log.Preparer
FROM Log
WHERE (((Log.State)=[Forms]![NewEntry_Form]![TxtState]) AND
((Log.Jurisdiction)=[Forms]![NewEntry_Form]![TxtJurisdiction]) AND
((Log.Company)=[Forms]![NewEntry_Form]![TxtCoNo]) AND
((Log.DueDate)=[Forms]![NewEntry_Form]![TxtDueDate]) AND
((Log.Preparer)=[Forms]![NewEntry_Form]![TxtPrep]));
我不明白我哪里出错了。编写VBA脚本以插入新记录然后立即使用表单中的信息更新该记录会更容易吗?
谢谢!我是新人。
莎拉答案 0 :(得分:0)
如果该记录与您的表单匹配,您所做的就是将记录从日志插入到日志中。试试这个:
Sub InsertRecord()
Dim SQL As String
SQL = ""
SQL = SQL & "INSERT INTO Log ( State, Jurisdiction, Company, DueDate, Preparer )" & vbCrLf
SQL = SQL & "VALUES ("
SQL = SQL & Me.TxtState.Value & ", " & vbCrLf
SQL = SQL & Me.TxtJurisdiction.Value & ", " & vbCrLf
SQL = SQL & Me.TxtCoNo.Value & ", " & vbCrLf
SQL = SQL & Me.TxtDueDate.Value & ", " & vbCrLf
SQL = SQL & Me.TxtPrep.Value & ")"
CurrentDb.Execute SQL
End Sub
答案 1 :(得分:0)
我最终使用VBA
Private Sub CmdAdd_Click()
'add data to table
CurrentDb.Execute "INSERT INTO FileInfo(Company, State, Jurisdiction, Taxtype, acctno, frequency, filemeth, pymtmeth, month, duedate, preparer, reviewer) " & _
" VALUES(" & Me.TxtCoNo & ",'" & Me.TxtState & "','" & Me.TxtJurisdiction & "','" & _
Me.TxtTaxType & "','" & Me.TxtAcctNo & "','" & Me.TxtFrequency & "','" & _
Me.txtFileMeth & "','" & Me.txtPymtMeth & "','" & _
Me.TxtMonth & "','" & Me.TxtDueDate & "','" & Me.TxtPrep & "','" & Me.TxtReviewer & "')"
FileInfosubform.Form.Requery