Access交流中心

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

变量未定义

王锋  发表于:2012-07-04 21:47:56  
复制

Public Function cz(ddID As String, pmjm As Long)     '在此处黄色标记系统提示"变量未定义"
Dim cnn1 As New ADODB.Connection
Dim rst2 As New ADODB.Recordset
Dim comml As New ADODB.Command
Dim temp As String
Dim x As Integer
Set cnn1 = CurrentProject.Connection 
    With comml
       .ActiveConnection = cnn                   
       .CommandText = "select 剩余数量 from 剩余数量计算表 where 订单ID=ddid and 品名简码ID=pmjm"

       .Execute                                
    End With
    rst2.Open comm1
If rst2.RecordCount = 1 Then
x = rst2("剩余数量")
Else
x = Null
End If
cz = x
Set rst2 = Nothing
rst2.Close
End Function

 

系统提示变量未定义,请问问题出在哪儿?

 

Top
风行 发表于:2012-07-05 09:26:13
Public Function cz(ddID As String, pmjm As Long) as long    

王锋 发表于:2012-07-05 11:03:36
谢谢,加上 as long 后仍然提示变量未定义

cspa 发表于:2012-07-05 13:06:26

Public Function cz(ddID As String, pmjm As Long)     '在此处**标记系统提示"变量未定义"
Dim cnn1 As New ADODB.Connection
Dim rst2 As New ADODB.Recordset
Dim comml As New ADODB.Command
Dim temp As String
Dim x As Integer
Set cnn1 = CurrentProject.Connection 
    With comml
       .ActiveConnection = cnn                   
       .CommandText = "select 剩余数量 from 剩余数量计算表 where 订单ID=ddid and 品名简码ID=pmjm"

       .Execute                                
    End With
    rst2.Open comm1     '是不是comm1未定义? 它与comml很象哦,可能会搞错  
If rst2.RecordCount = 1 Then
x = rst2("剩余数量")
Else
x = Null
End If
cz = x
Set rst2 = Nothing
rst2.Close
End Function



cspa 发表于:2012-07-05 13:58:24

补充:

Public Function cz(ddID As String, pmjm As Long)     '在此处**标记系统提示"变量未定义"
Dim cnn1 As New ADODB.Connection
Dim rst2 As New ADODB.Recordset
Dim comml As New ADODB.Command
Dim temp As String
Dim x As Integer
Set cnn1 = CurrentProject.Connection 
    With comml
       .ActiveConnection = cnn    'cnn也没定义,似乎应是cnn1               
       .CommandText = "select 剩余数量 from 剩余数量计算表 where 订单ID='" & ddid & "' and 品名简码ID=" & pmjm & ";"""     '此句这样似乎才能将变量值赋与相应字段           

       .Execute                                
    End With
    rst2.Open comm1     '是不是comm1未定义? 它与comml很象哦,可能会搞错  
If rst2.RecordCount = 1 Then
x = rst2("剩余数量")
Else
x = Null
End If
cz = x
Set rst2 = Nothing
rst2.Close
End Function



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