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