|
楼主 |
发表于 2003-12-18 13:53
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
我想从course表中查找一个课程名等于给定名称的记录,然后取此记录的课程号字段,组织成SQL以后再插入到score表中.
Private Sub AddRecord_Click()
On Error GoTo Err_AddRecord_Click
Dim courseid As String
'Dim rst As adodb.Recordset
Dim appAccess As New Access.Application
appAccess.OpenCurrentDatabase ("C:\Documents and Settings\Administrator\桌面\lijun2.mdb")
'Set rst = New adodb.Recordset
Set rst = Me.Recordset
'MsgBox "SELECT 课程号 from course where 课程名='" & coursename & "'," & appAccess.CurrentDb.Connection, adOpenKeyset, adLockOptimistic
MsgBox "SELECT 课程号 from course where 课程名='" & coursename & "'"
rst.Open "SELECT 课程号 from course where 课程名='" & coursename & "'"
'Set rst = OpenRecordset("SELECT 课程号 from course where 课程名='" & coursename & "'")
courseid = rst.Fields(0)
DoCmd.RunSQL ("insert into score values('" & stuid & "', '" & courseid & "'," & stuscore & ")")
Exit_AddRecord_Click:
Exit Sub
Err_AddRecord_Click:
MsgBox Err.Description
Resume Exit_AddRecord_Click
End Sub |
|