If isExisting Then
Set searchCustomerByID = re_customer
Else
Set searchCustomerByID = Null //这句出错
End IfsearchCustomerByID是function name
Set searchCustomerByID = re_customer
Else
Set searchCustomerByID = Null //这句出错
End IfsearchCustomerByID是function name
这样行不行
end function
把返回类型改为变体型
searchCustomerByID = Null 就正确了
Dim re_customer As customer
Dim isExisting As Boolean
Set re_customer = New customer
Set in_util = New util
Set db = OpenDatabase("", False, False, "ODBC;DSN=CTIDSN;UID=sa;PWD=;TIMEOUT=180")
Dim sqlcmd As String
sqlcmd = "select * from Customer where "
If Form1.Check_UT Then
sqlcmd = sqlcmd & " UCASE(RTrim(Ltrim(customer_id) ) )"
Else
sqlcmd = sqlcmd & "customer_id"
End If
sqlcmd = sqlcmd & " = " & in_util.addQuote(Trim(UCase(id)))
'MsgBox (sqlcmd)
Set rs = db.OpenRecordset(sqlcmd)
If rs.EOF Then
isExisting = False
Else
'MsgBox ("FIND")
re_customer.id = rs![customer_id]
re_customer.last_name = rs![CUSTOMER_LAST_NAME]
re_customer.phone = rs![PHONE_NUMBER]
re_customer.pps_no = rs![pps_no]
isExisting = True
End If
'Close all of connection
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
'If isExisting Then
Set searchCustomerByID = re_customer
'Else
' Set searchCustomerByID = re_customer
'End If
End Function
下面是调用的代码
Set re_customer = gb_CustomerDB.searchCustomerByID(customer_id)
If re_customer Then //这句又应怎写?
MsgBox ("Can not find the customer,Customer ID:" & customer_id)
Else
Form1.Command_Update.Enabled = True
Call setUpCustomerInfo(re_customer)
End If
为什么不知道
Set searchCustomerByID =nothing
?
Dim re_customer As customer
'Dim isExisting As Boolean
Set in_util = New util
Set db = OpenDatabase("", False, False, "ODBC;DSN=CTIDSN;UID=sa;PWD=;TIMEOUT=180")
Dim sqlcmd As String
sqlcmd = "select * from Customer where "
If Form1.Check_UT Then
sqlcmd = sqlcmd & " UCASE(RTrim(Ltrim(customer_id) ) )"
Else
sqlcmd = sqlcmd & "customer_id"
End If
sqlcmd = sqlcmd & " = " & in_util.addQuote(Trim(UCase(id)))
'MsgBox (sqlcmd)
Set rs = db.OpenRecordset(sqlcmd)
'If rs.EOF Then
'isExisting = False
'Else
If Not rs.Eof Then
'MsgBox ("FIND")
Set re_customer = New customer
re_customer.id = rs![customer_id]
re_customer.last_name = rs![CUSTOMER_LAST_NAME]
re_customer.phone = rs![PHONE_NUMBER]
re_customer.pps_no = rs![pps_no]
'isExisting = True
Set searchCustomerByID = re_customer
Set re_customer = Nothing
End If
'Close all of connection
Set in_util = Nothing
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
'If isExisting Then
' Set searchCustomerByID = re_customer
'Else
' Set searchCustomerByID = re_customer
'End If
End Function
下面是调用的代码
Set re_customer = gb_CustomerDB.searchCustomerByID(customer_id)
If re_customer is nothing Then
MsgBox ("Can not find the customer,Customer ID:" & customer_id)
Else
Form1.Command_Update.Enabled = True
Call setUpCustomerInfo(re_customer)
End If