Passing parameters to action stored procedures using ADO, in Access Project

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • zlatko

    Passing parameters to action stored procedures using ADO, in Access Project

    There is a form in an Access Project (.adp, Access front end with SQL
    Server) for entering data into a table for temporary storing. Then, by
    clicking a botton, several action stored procedures (update, append) should
    be activated in order to transfer data to other tables.

    I tried to avoid any coding in VB, as I am not a professional, but I have
    found a statement in an article, that, unlike select queries, form's Input
    Property can't be used for action queries. Therefore, parameters can be
    passed to action stored procedure only by using ADO through VB.

    As I'm not very familiar with VB, I had to search in literature.

    So, this is a solution based on creating Parameter object in ADO and then
    appending values to Parameter collection.

    Please, consider the following procedure I created for passing parameters
    from form's control objects (Text boxes) to a stored procedure
    DTKB_MB_UPDATE:





    Private Sub Command73_Click ()



    Dim cmd As ADODB.Command



    Set cmd = New ADODB.Command



    cmd.ActiveConne ction = CurrentProject. Connection

    cmd.CommandText = "DTKB_MB_UPDATE "

    cmd.CommandType = adCmdStoredProc



    Dim par As ADODB.Parameter



    Set par = cmd.CreateParam eter("@DATE", adDBTimeStamp, adParamInput)

    cmd.Parameters. Append par

    Set par = cmd.CreateParam eter("@BATCH_NU MBER", adVarWChar, adParamInput, 50)

    cmd.Parameters. Append par

    Set par = cmd.CreateParam eter("@STATUS", adVarWChar, adParamInput, 50)

    cmd.Parameters. Append par

    Set par = cmd.CreateParam eter("@DEPARTME NT", adVarWChar, adParamInput, 50)

    cmd.Parameters. Append par

    Set par = cmd.CreateParam eter("@PRODUCTI ON", adVarWChar, adParamInput, 50)

    cmd.Parameters. Append par

    Set par = cmd.CreateParam eter("@SAMPLING _TYPE", adVarWChar, adParamInput,
    50)

    cmd.Parameters. Append par



    cmd.Parameters( "@DATE") = Me.DATE

    cmd.Parameters( "@BATCH_NUMBER" ) = Me.BATCH_NUMBER

    cmd.Parameters( "@STATUS") = Me.STATUS

    cmd.Parameters( "@DEPARTMEN T") = Me.DEPARTMENT

    cmd.Parameters( "@PRODUCTIO N") = Me.PRODUCTION

    cmd.Parameters( "@SAMPLING_TYPE ") = Me.SAMPLING_TYP E



    cmd.Execute



    Set cmd = Nothing



    End Sub





    Unfortunately, when clicking on the botton, the following error apears:



    "Run-time error'-2147217913 (80040e07)':Syn tax error converting datetime
    from character string."



    Obviously, there is some problem regarding parameter @DATE. In SQL Server it
    is datetime, on the form's onbound text box it is short date (dd.mm.yyyy)
    data type. I have found in literature that in ADO it should be
    adDBTimeStamp.

    So, what is the problem ?



    Greetings,



    Zlatko


  • John Bell

    #2
    Re: Passing parameters to action stored procedures using ADO, in Access Project

    Hi

    I replied in microsoft.publi c.sqlserver.pro gramming, please don't post
    separately to multiple groups.

    John

    "zlatko" <zlatko.matic1@ sb.htnet.hr> wrote in message
    news:cnps98$u9c $1@ls219.htnet. hr...[color=blue]
    > There is a form in an Access Project (.adp, Access front end with SQL
    > Server) for entering data into a table for temporary storing. Then, by
    > clicking a botton, several action stored procedures (update, append)
    > should
    > be activated in order to transfer data to other tables.
    >
    > I tried to avoid any coding in VB, as I am not a professional, but I have
    > found a statement in an article, that, unlike select queries, form's Input
    > Property can't be used for action queries. Therefore, parameters can be
    > passed to action stored procedure only by using ADO through VB.
    >
    > As I'm not very familiar with VB, I had to search in literature.
    >
    > So, this is a solution based on creating Parameter object in ADO and then
    > appending values to Parameter collection.
    >
    > Please, consider the following procedure I created for passing parameters
    > from form's control objects (Text boxes) to a stored procedure
    > DTKB_MB_UPDATE:
    >
    >
    >
    >
    >
    > Private Sub Command73_Click ()
    >
    >
    >
    > Dim cmd As ADODB.Command
    >
    >
    >
    > Set cmd = New ADODB.Command
    >
    >
    >
    > cmd.ActiveConne ction = CurrentProject. Connection
    >
    > cmd.CommandText = "DTKB_MB_UPDATE "
    >
    > cmd.CommandType = adCmdStoredProc
    >
    >
    >
    > Dim par As ADODB.Parameter
    >
    >
    >
    > Set par = cmd.CreateParam eter("@DATE", adDBTimeStamp, adParamInput)
    >
    > cmd.Parameters. Append par
    >
    > Set par = cmd.CreateParam eter("@BATCH_NU MBER", adVarWChar, adParamInput,
    > 50)
    >
    > cmd.Parameters. Append par
    >
    > Set par = cmd.CreateParam eter("@STATUS", adVarWChar, adParamInput, 50)
    >
    > cmd.Parameters. Append par
    >
    > Set par = cmd.CreateParam eter("@DEPARTME NT", adVarWChar, adParamInput, 50)
    >
    > cmd.Parameters. Append par
    >
    > Set par = cmd.CreateParam eter("@PRODUCTI ON", adVarWChar, adParamInput, 50)
    >
    > cmd.Parameters. Append par
    >
    > Set par = cmd.CreateParam eter("@SAMPLING _TYPE", adVarWChar, adParamInput,
    > 50)
    >
    > cmd.Parameters. Append par
    >
    >
    >
    > cmd.Parameters( "@DATE") = Me.DATE
    >
    > cmd.Parameters( "@BATCH_NUMBER" ) = Me.BATCH_NUMBER
    >
    > cmd.Parameters( "@STATUS") = Me.STATUS
    >
    > cmd.Parameters( "@DEPARTMEN T") = Me.DEPARTMENT
    >
    > cmd.Parameters( "@PRODUCTIO N") = Me.PRODUCTION
    >
    > cmd.Parameters( "@SAMPLING_TYPE ") = Me.SAMPLING_TYP E
    >
    >
    >
    > cmd.Execute
    >
    >
    >
    > Set cmd = Nothing
    >
    >
    >
    > End Sub
    >
    >
    >
    >
    >
    > Unfortunately, when clicking on the botton, the following error apears:
    >
    >
    >
    > "Run-time error'-2147217913 (80040e07)':Syn tax error converting datetime
    > from character string."
    >
    >
    >
    > Obviously, there is some problem regarding parameter @DATE. In SQL Server
    > it
    > is datetime, on the form's onbound text box it is short date (dd.mm.yyyy)
    > data type. I have found in literature that in ADO it should be
    > adDBTimeStamp.
    >
    > So, what is the problem ?
    >
    >
    >
    > Greetings,
    >
    >
    >
    > Zlatko
    >
    >[/color]


    Comment

    • Erland Sommarskog

      #3
      Re: Passing parameters to action stored procedures using ADO, in Access Project

      zlatko (zlatko.matic1@ sb.htnet.hr) writes:[color=blue]
      > There is a form in an Access Project (.adp, Access front end with SQL
      > Server) for entering data into a table for temporary storing. Then, by
      > clicking a botton, several action stored procedures (update, append)
      > should be activated in order to transfer data to other tables.
      >
      > I tried to avoid any coding in VB, as I am not a professional, but I have
      > found a statement in an article, that, unlike select queries, form's Input
      > Property can't be used for action queries. Therefore, parameters can be
      > passed to action stored procedure only by using ADO through VB.
      >
      > As I'm not very familiar with VB, I had to search in literature.
      >...
      > Set par = cmd.CreateParam eter("@DATE", adDBTimeStamp, adParamInput)
      >...
      > cmd.Parameters( "@DATE") = Me.DATE
      > Unfortunately, when clicking on the botton, the following error apears:
      >
      > "Run-time error'-2147217913 (80040e07)':Syn tax error converting datetime
      > from character string."
      >
      > Obviously, there is some problem regarding parameter @DATE. In SQL
      > Server it is datetime, on the form's onbound text box it is short date
      > (dd.mm.yyyy) data type. I have found in literature that in ADO it should
      > be adDBTimeStamp.[/color]

      This is more likely to be a Visual Basic or Access problem than an
      SQL Server problem. The code looks good to me, but I don't really know
      what's in Me.DATE.

      There are things to check:

      o Verify that the error actually is on the line where you assign to
      cmd.Parameters( "@DATE").
      o Check that the regional settings of your computer really is one
      which uses dd.mm.yyyy as date format, and you are not accidently not
      running with, for instance, US English settings.


      --
      Erland Sommarskog, SQL Server MVP, esquel@sommarsk og.se

      Books Online for SQL Server SP3 at
      Transform your business with a unified data platform. SQL Server 2019 comes with Apache Spark and Hadoop Distributed File System (HDFS) for intelligence over all your data.

      Comment

      Working...