Public Function GetMaxNo(Noname As String, LikeStr As String) As String
Dim comm As New ADODB.Command
With comm
  .ActiveConnection = CurrentProject.Connection
  .Parameters.Append .CreateParameter("@return_value", adInteger, adParamReturnValue)
   .Parameters.Append .CreateParameter("@NOSName", adBSTR, adParamInput, 4, Noname)
   .Parameters.Append .CreateParameter("@LikeStr", adBSTR, adParamInput, 8, LikeStr)
   .Parameters.Append .CreateParameter("@MaxNO", adBSTR, adParamOutput, 16)
  .CommandType = adCmdStoredProc
  .CommandText = "ProcSys_GetMaxNO"
  .Execute
End With
If comm.Parameters(0).Value = 0 Then
  If IsNull(comm.Parameters(3).Value) Then
  GetMaxNo = LikeStr & "0001"
  Else
  GetMaxNo = LikeStr & Format(Trim(comm.Parameters(3).Value), "0000")
  End If
Else
  GetMaxNo = ""
End If
Set comm = Nothing
End Function



  CurrentProject.Connection.Execute " exec ProcMK_CopyNewQU '" & Me.QUNO & "','" & TempN & "'," & TEMPNO + 1 & ""

==========================================
Attribute VB_Name = "modPublic"
Option Compare Database
Option Explicit


'''''返回一个记录集,SQL可以是一个SQL语句,或者是一个存储过程。
''''' 如:select * from XXX  或   存储过程1 'abc'
Function GetRecordset(sql As String) As Recordset
  Set GetRecordset = CurrentProject.Connection.Execute(sql)
End Function

''''返回一个记录
Function GetResult(sql As String) As Variant
  Dim r As Recordset
 
  Set r = GetRecordset(sql)
  If r.RecordCount = 0 Then
    GetResult = Null
  Else
    GetResult = r.GetString
  End If
End Function

Function GetParStr(ParamArray p() As Variant) As String
  Dim i As Integer
  Dim s As String
  Dim v As Variant

  For i = 0 To UBound(p(0))
    v = p(0)(i)
    Select Case TypeName(v)
      Case "String":
        s = s & "N'" & v & "'"
      Case "Date":
        s = s & GetDateValue(CDate(v), True)
      Case Else:
        s = s & v
    End Select
    If i <> UBound(p(0)) Then s = s + ","
  Next i
  GetParStr = s
End Function
'''执行存储过程并返回记录
Function GetTSQLProc(ProcName As String, ParamArray p() As Variant) As Recordset
  Set GetTSQLProc = GetRecordset("exec " + ProcName + " " + GetParStr(p()))
End Function
'''求单个TSQL函数的单个值
Function GetTSQLFuncResult(FuncName As String, ParamArray p() As Variant) As Variant
  GetTSQLFuncResult = GetResult("select " + FuncName + "(" + GetParStr(p) + ")")
End Function
'''求服务器日期
Function GetServerDate() As Date
  GetServerDate = Format(GetResult("select getdate()"), "yyyy-mm-dd")
End Function

posted on 2005-01-19 09:27  James Wong   阅读(2211)  评论(0)    收藏  举报