Results 1 to 4 of 4
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672

    Passing Params To Stored Procedure

    I asked a question a few days ago about how to hide/unhide text box/labels on a user form here: https://www.accessforums.net/showthread.php?t=65341



    I now need a way to pass the values into a SQL Stored Procedure - which I will use an ADODB connection and pass the params that way. Now here is where I am unclear on how to code....

    Say I have 4 text boxes on the user form that could be populated, obviously I would need 4 params in the stored procedure. Would it be best to set things up like this in my VBA
    Code:
    With cmd.Parameters
        .Append cmd.CreateParameter("Param1", adVarChar, adParamInput, 8000, textbox1.Value)
        .Append cmd.CreateParameter("Param2", adVarChar, adParamInput, 8000, textbox2.Value)
        .Append cmd.CreateParameter("Param3", adVarChar, adParamInput, 8000, textbox3.Value)
        .Append cmd.CreateParameter("Param4", adVarChar, adParamInput, 8000, textbox4.Value)
    End With
    And check for null values on the SQL side of things?

  2. #2
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349

  3. #3
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    That shows how to pass parameters. My question is about how to handle null parameters.

  4. #4
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    Apologies, mis-read.

    For parameters where the input to the proc can be Null, here is an example:

    Set prmGeneral = .CreateParameter("XYZ", adInteger, adParamInput)
    If lngNewStatus = 0 Then
    prmGeneral.Value = Null
    Else
    prmGeneral.Value = lngNewStatus
    End If
    .Parameters.Append prmGeneral

    Then in the proc check for Null if required and process accordingly.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Help with SQL stored procedure
    By emmahope206 in forum Access
    Replies: 1
    Last Post: 05-24-2016, 05:03 PM
  2. Replies: 3
    Last Post: 10-27-2015, 02:37 PM
  3. Replies: 33
    Last Post: 09-25-2015, 08:39 AM
  4. Replies: 2
    Last Post: 08-29-2012, 08:01 AM
  5. Passing variable values to Stored Procedure
    By rodrigopcnet in forum Access
    Replies: 1
    Last Post: 04-14-2010, 10:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums