Access交流中心

北京 | 上海 | 天津 | 重庆 | 广州 | 深圳 | 珠海 | 汕头 | 佛山 | 中山 | 东莞 | 南京 | 苏州 | 无锡 | 常州 | 南通 | 扬州 | 徐州 | 杭州 | 温州 | 宁波 | 台州 | 福州 | 厦门 | 泉州 | 龙岩 | 合肥 | 芜湖 | 成都 | 遂宁 | 长沙 | 株洲 | 湘潭 | 武汉 | 南昌 | 济南 | 青岛 | 烟台 | 潍坊 | 淄博 | 济宁 | 太原 | 郑州 | 石家庄 | 保定 | 唐山 | 西安 | 大连 | 沈阳 | 长春 | 昆明 | 兰州 | 哈尔滨 | 佳木斯 | 南宁 | 桂林 | 海口 | 贵阳 | 西宁 | 乌鲁木齐 | 包头 |

报错3021

chaoxing  发表于:2014-03-26 05:05:18  
复制

Private Sub Form_Load()
Dim rst As Object
Dim strsql As String
Dim currentid As String
currentid = Form_FRMYG_SG_LIST.Form.ygid
strsql = "select*from tblcodeyg where ygid=""&currentid&"""
Set rst = CurrentDb.OpenRecordset(strsql, dbOpenDynaset)
rst.MoveFirst
Me.txtygxm = rst!ygxm
rst.Close
Set rst = Nothing

End Sub

 

 

报错3021

 

 

 

rst.MoveFirst

 

 

Top
cspa 发表于:2014-03-26 09:26:11
3021是无当前记录,根据你的代码可能是strsql = "select*from tblcodeyg where ygid=""&currentid&"""的运行结果没有符合条件的记录。
你在程序中应加上一个判断语句,对此情况做出处理。

chaoxing 发表于:2014-03-26 20:27:49
谢谢!怎么样设判断名呢?

zhaoyoulong 发表于:2014-03-27 08:42:41

strsql = "select*from tblcodeyg where ygid=""&currentid&"""

改为:

strsql = "select * from tblcodeyg where ygid=‘" & currentid & "’"

试试



cspa 发表于:2014-03-27 09:03:03

Private Sub Form_Load()
Dim rst As Object
Dim strsql As String
Dim currentid As String
currentid = Form_FRMYG_SG_LIST.Form.ygid

strsql = "select*from tblcodeyg where ygid='"¤tid&"'"
Set rst = CurrentDb.OpenRecordset(strsql, dbOpenDynaset)
If rst.RecordCount >= 1 Then

    rst.MoveFirst
  Else

    MsgBox "无符合条件的记录!"

    exit sub

end if

Me.txtygxm = rst!ygxm
rst.Close
Set rst = Nothing

End Sub

 



总记录:4篇  页次:1/1 9 1 :