Results 1 to 3 of 3
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows XP Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672

    Run Sql Stored Procedure And Populate Form With Results

    I know how to use DAO to run an embedded SQL Statement, but now I need to return 4 - 5 fields from my query so I was going to create a SQL stored procedure and execute that, then return the results. This is what I use for one field to return from embedded SQL
    Code:
    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("SELECT monsterskill FROM Feature WHERE monsternum = " & Me.txtmonsternum & " ")
    Me.txtskill = rs!monsterskill
    rs.Close
    Set rs = Nothing
    I know I can use this to execute a stored procedure from Access VBA
    Code:
    Dim cmd As ADODB.Command
    Set cmd = New ADODB.Command
    cmd.ActiveConnection = "Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=[DB];Data Source=[PC];Integrated Security=SSPI;"
    cmd.CommandType = adCmdStoredProc
    cmd.CommandText = "sp_GetMonsterInfo"
    cmd.Parameters.Append cmd.CreateParameter("@monsternum", adVarChar, adParamInput, 255, param)
    cmd.Execute
    This stored procedure runs a select statement to return 4 fields. What I want to do is execute the stored procedure
    Code:
    Select monstername, monsterskill, monsterclass, monstergenus from monsterdata where monsternum = @monsternum;
    Then set an access form like so (of course the Me![] are the field names on the form and the right of the equal sign is what is returned from the database)
    Me![Monster Name] = monstername
    Me![Monster Skill] = monsterskill
    Me![Monster Class] = monsterclass


    Me![Monster Genus] = monster genus

    How would I achieve this result? And yes, each monsternum would only return ONE value for each field.

    EDIT -- This project will be performed in Acces 2013

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    once you execute the SP,
    open a form on a query to pull these results.

  3. #3
    jo15765's Avatar
    jo15765 is offline Expert
    Windows XP Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Quote Originally Posted by ranman256 View Post
    once you execute the SP,
    open a form on a query to pull these results.
    I do not follow what you mean by this?

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: 33
    Last Post: 09-25-2015, 08:39 AM
  3. Replies: 1
    Last Post: 04-13-2010, 12:18 PM
  4. Replies: 0
    Last Post: 10-04-2009, 04:11 AM
  5. stored procedure return value to access form
    By rbw940 in forum Programming
    Replies: 0
    Last Post: 10-13-2008, 01:31 PM

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