设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1610|回复: 6
打印 上一主题 下一主题

[窗体] 查询之后子窗体中的数据无法更新

[复制链接]
跳转到指定楼层
1#
发表于 2009-4-21 17:31:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Me.查询结果.Form.RecordSource = strsql
Me.查询结果.Form.Requery

用以上方式刷新,当查询条件为主键时,是可以更新的,但是查询其他字段就不能更新了
请大家帮忙看下
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2009-4-21 17:59:49 | 只看该作者
一般这句Me.查询结果.Form.RecordSource = strsql就可以了,
你的问题不知道到底是如何,请传实例。
3#
 楼主| 发表于 2009-4-21 19:46:09 | 只看该作者

我就是做了这样子的一个通讯录,按下查询就会在下面“查询结果”里面显示查找到的记录。查询的事件响应代码如下:
Private Sub Command46_Click()
On Error GoTo Err_Command46_Click
Dim qry_tmp As QueryDef
Dim dbs_itsr As Database
Dim strwhere As String
Dim strsql As String

Dim length As Integer
Set dbs_itsr = CurrentDb()
strsql = "SELECT * FROM Contract"
strwhere = ""
If Not IsNull(Me.学号) And Not Me.学号 = "" Then
If Me.Check1.Value = False Then
strwhere = strwhere & "Contract.学号='" & Me.学号 & "' " & Me.LogicOp1 & " "
Else
strwhere = strwhere & "Contract.学号 LIKE '*" & Me.学号 & "*' " & Me.LogicOp1 & " "
End If
length = Len(Me.LogicOp1) + 2
End If
If Not IsNull(Me.姓名) And Not Me.姓名 = "" Then
If Me.Check2.Value = False Then
strwhere = strwhere & "Contract.姓名='" & Me.姓名 & "' " & Me.LogicOp2 & " "
Else
strwhere = strwhere & "Contract.姓名 LIKE '*" & Me.姓名 & "*' " & Me.LogicOp2 & " "
End If
length = Len(Me.LogicOp2) + 2
End If
If Not IsNull(Me.班级) And Not Me.班级 = "" Then
If Me.Check3.Value = False Then
strwhere = strwhere & "Contract.班级='" & Me.班级 & "' " & Me.LogicOp3 & " "
Else
strwhere = strwhere & "Contract.班级 LIKE '*" & Me.班级 & "*' " & Me.LogicOp3 & " "
End If
length = Len(Me.LogicOp3) + 2
End If
If Not IsNull(Me.专业) And Not Me.专业 = "" Then
If Me.Check4.Value = False Then
strwhere = strwhere & "Contract.专业='" & Me.专业 & "' " & Me.LogicOp4 & " "
Else
strwhere = strwhere & "Contract.专业 LIKE '*" & Me.专业 & "*' " & Me.LogicOp4 & " "
End If
length = Len(Me.LogicOp4) + 2
End If
If Not IsNull(Me.电话) And Not Me.电话 = "" Then
If Me.Check5.Value = False Then
strwhere = strwhere & "Contract.电话='" & Me.电话 & "' " & Me.LogicOp5 & " "
Else
strwhere = strwhere & "Contract.电话 LIKE '*" & Me.电话 & "*' " & Me.LogicOp5 & " "
End If
length = Len(Me.LogicOp5) + 2
End If
If Not IsNull(Me.邮件) And Not Me.邮件 = "" Then
If Me.Check6.Value = False Then
strwhere = strwhere & "Contract.邮箱地址='" & Me.邮件 & "' " & Me.LogicOp6 & " "
Else
strwhere = strwhere & "Contract.邮箱地址 LIKE '*" & Me.邮件 & "*' " & Me.LogicOp6 & " "
End If
length = Len(Me.LogicOp6) + 2
End If
If Not IsNull(Me.性别) And Not Me.性别 = "" And Not Me.性别 = "任意" Then
strwhere = strwhere & "Contract.性别='" & Me.性别 & "' " & Me.LogicOp7 & " "
length = Len(Me.LogicOp7) + 2
End If
If Not IsNull(Me.年龄1) And Not IsNull(Me.年龄2) And Not Me.年龄1 = "" And Not Me.年龄2 = "" And Not Me.年龄1 = "任意" And Not Me.年龄2 = "任意" Then
If Me.年龄1 = Me.年龄2 Then
strwhere = strwhere & "Contract.年龄=" & Me.年龄1
End If
If Me.年龄1 > Me.年龄2 Then
strwhere = strwhere & "Contract.年龄<" & Me.年龄1 & " AND Contract.年龄>" & Me.年龄2
End If
If Me.年龄1 < Me.年龄2 Then
strwhere = strwhere & "Contract.年龄<" & Me.年龄2 & " AND Contract.年龄>" & Me.年龄1
End If
length = 0
End If

If Len(strwhere) > 0 Then
strwhere = Left(strwhere, Len(strwhere) - length)
End If
If Len(strwhere) > 0 Then
strsql = strsql & " WHERE " & strwhere & ";"
End If
For Each qry_tmp In dbs_itsr.QueryDefs
If qry_tmp.Name = "ContractQuery" Then
dbs_itsr.QueryDefs.Delete qry_tmp.Name
End If
Next qry_tmp
Set qry_tmp = dbs_itsr.CreateQueryDef("ContractQuery", strsql)
On Error GoTo Err_Command46_Click

Me.查询结果.Form.RecordSource = strsql
Me.查询结果.Form.Requery

Me.Refresh

Exit_Command46_Click:
Exit Sub
Err_Command46_Click:
MsgBox Err.Description
Resume Exit_Command46_Click
End Sub
4#
发表于 2009-4-21 20:11:30 | 只看该作者
长长的代码,看得 晕晕的。
请传例子。
5#
 楼主| 发表于 2009-4-21 20:21:00 | 只看该作者
多谢啦~ 4# Henry D. Sy

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
6#
发表于 2009-4-21 20:47:31 | 只看该作者
07的帮不了您。
7#
 楼主| 发表于 2009-4-21 20:52:45 | 只看该作者
6# Henry D. Sy 哦,多谢啦~
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-9-21 22:15 , Processed in 0.095825 second(s), 32 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表