[英]Ms access adding data to tables via forms
I am currently using ms access forms to view data used within tables I have created, to make it more user friendly. 我目前正在使用ms访问表单来查看在我创建的表中使用的数据,以使其更加用户友好。
Tables are listed below: 下表列出:
The training table is populated by using the primary keys from the other tables. 使用其他表中的主键填充培训表。
Fields listed below: 下面列出的字段:
I want to be able to add to the tblTraining table using text boxes and combo boxes on the ms access form. 我希望能够使用ms访问表单上的文本框和组合框添加到tblTraining表中。 However, the issue I am having is that only a number format can be added to the table.
但是,我遇到的问题是只能将数字格式添加到表中。 Is there a way that I can insert text and it would find the primary linked to it and adds it to the table.
有没有一种方法可以插入文本,它将找到与之链接的主文本并将其添加到表中。
For example.. 例如..
The text fields that I have on the form are: 我在表单上的文本字段是:
and the fields on the Training table is listed above. 并且“培训”表上的字段已在上面列出。
Here is an example of the code I used to add employees to the tblEmployee table: 这是我用来将雇员添加到tblEmployee表中的代码的示例:
Private Sub btnAdd_Click()
If Me.txtEmployeeID.Tag & "" = "" Then
CurrentDb.Execute "INSERT INTO tblEmployee(EmployeeID, FirstName, Surname) " & _
"VALUES (" & Me.txtEmployeeID & " , '" & Me.txtFirstName & "', '" & Me.txtSurname & "')"
MsgBox ("Employee has been added.")
Else
CurrentDb.Execute "UPDATE tblEmployee " & _
" SET EmployeeID = " & Me.txtEmployeeID & _
", FirstName = '" & Me.txtFirstName & "'" & _
", Surname = '" & Me.txtSurname & "'" & _
" WHERE EmployeeID = " & Me.txtEmployeeID.Tag
MsgBox ("Employee has been updated.")
End If
btnClear_Click
Me.txtEmployeeID.SetFocus
Me.subformEmployee.Form.Requery
End Sub
Thanks. 谢谢。
I'm assuming your tables are structured like below 我假设您的表格结构如下
tblCourse: ID autonumber - PRIMARY KEY tblCourse:ID自动编号-主键
tblEmployee: ID autonumber- PRIMARY KEY tblEmployee:ID自动编号-主键
tblReason: ID autonumber - PRIMARY KEY tblReason:ID自动编号-主键
tblTraining: ID autonumber - PRIMARY KEY EmployeeID long integer - FOREIGN KEY REFERENCES tblEmployee(ID) CourseID long integer - FOREIGN KEY REFERENCES tblCourse(ID) ReasonID long integer - FOREIGN KEY REFERENCES tblReason(ID) tblTraining:ID自动编号-主键EmployeeID长整数-外键引用tblEmployee(ID)CourseID长整数-异键引用tblCourse(ID)ReasonID长整数-异键引用tblReason(ID)
if this is correct, then to answer your question, no, you cannot add text to these fields on the table. 如果这是正确的,那么要回答您的问题,不,您不能在表的这些字段中添加文本。 It has to be a number due to the relationship structure you have in place.
由于您具有适当的关系结构,因此必须为数字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.