Subform Problem

Apr 10, 2006

The question I have is a bit complicated but I'm hoping someone can help me out.

I am using SQL Express as the back end database, connecting through MS Access and using VBA to do the code. I have created a project in Access and in it I have a form in which I created a subform. The subform has a stored procedure as it's record source, the problem is that in order to keep the data in the subform in sync with the data in the form the stored procedure needs a parameter to retrieve the correct data. How does one pass that parameter as well as the stored procedure on the record source setting?

I have been able to do combolist population, or data retrieval using stored procedure but it doesn't seem to be working with populating the subform.

'create a connection to database
Set Cnxn = New ADODB.Connection
Cnxn.Open strCnxn

'Populate the PO Number text box
Dim cmdUnitPrice As ADODB.Command
Dim prmUnitPrice As ADODB.Parameter
Dim rstUnitPrice As ADODB.Recordset
Dim strSQLUnitPrice As String

'Define a command object to call stored procedure
Set cmdUnitPrice = New ADODB.Command
Set cmdUnitPrice.ActiveConnection = Cnxn

'set the criteria to the stored procedure called
strSQLUnitPrice = "sp_GetUnitPrice"
cmdUnitPrice.CommandText = strSQLUnitPrice
cmdUnitPrice.CommandType = adCmdStoredProc
cmdUnitPrice.CommandTimeout = 15

'define the stored procedure's input parameter
Set prmUnitPrice = New ADODB.Parameter
prmUnitPrice.Type = adInteger
prmUnitPrice.Size = 3
prmUnitPrice.Direction = adParamInput
prmUnitPrice.Value = intProdID
cmdUnitPrice.Parameters.Append prmUnitPrice

'create a recordset by executing the command
Set rstUnitPrice = cmdUnitPrice.Execute()

dblUnitPrice = rstUnitPrice.Fields(0)

rstUnitPrice.Close

Set rstUnitPrice = Nothing

In the case of a list I would use a while loop to enter all the values that the recordset returned.

Rodrigo

View 1 Replies


ADVERTISEMENT

Use Sql Statemetn To Query Subform.

Nov 16, 2006

I would like to filter a subform by using a sql statement in vba.

I want to be able to say. afterupdate on a combo box. select "*" where[excd]<>"ne" and [billstatus] = bu then select the items where [excd]="Ne" and [billstatus]<>= bu.

What I want is all the "BU bill status that [excd] does not equal "ne" and all the items were {excd] = ne but the bill status does not equal bu.



Hope H.

View 2 Replies View Related

Error Sorting Subform

Apr 20, 2006

Has anyone ever gotten this error message when sorting an Access Project subform based on an SQL table?

"column prefix [name of subform] does not match with the table name or alias used in the query".

I built a main parts form from a SQL table [Parts] using Access Project. I then added a subform [FSinvPARThistory] based on another SQL table [PartHistory] to record history for the part. The two are linked together using primary key 'ID'. I can sort the subform but then when I go to select another record on the main form I get the above error message.

Can you not sort a subform? If not, how can I prevent users from inadvertantly sorting a subform and getting the same message?

Thanks.

View 1 Replies View Related

Subform Problem With Unique-table-property Set In Access Adp

Jul 20, 2005

Dear All,W2000Office2000Access adpSQLserver DBProblem:Adding a new property for a company in the subform.The FIRST time I Select a property in combobox CPROP_PRP_ID the subform actstrange.1. The selected value doen't show in the combobox!2. The sortorder of the subform changes!Reselecting the same value in the combobox acts normal and adding gives noproblem.Adding a second property for the same company acts normal.Please HELP, I can't solve this problem!All specifications below.Tables:COMPANY: COM_ID, COM_NAME, etc.PROPERTY: PRP_ID, PRP_NAME, ETC.COMPANY_PROPERTY: CPROP_COM_ID, CPROP_PRP_ID, CPROP_VALUEFRM_COMPANY: source = table COMPANYSUBFRM_COMPRP:1. SubFrm source = view (see sql)SELECT COMPANY_PROPERTY.CPROP_COM_ID,COMPANY_PROPERTY.CPROP_PRP_ID,PROPERTY.PRP_NAME,COMPANY_PROPERTY.CPROP_VALUEFROM dbo.COMPANY_PROPERTY INNER JOINdbo.PROPERTY ONdbo.COMPANY_PROPERTY.CPROP_PRP_ID = dbo.PROPERTY.PRP_ID2. SubFrm: Order By = ViewComPrpsSubFrmSource.PRP_NAME to sort byPROPERTY.PRP_NAME3. SubFrm: Unique table = COMPANY_PROPERTY4. Controls:4.1.combobox that holds CPROP_PRP_ID (Rowsource=SELECT PRP_ID, PRP_NAME FROMPROPERTY WHERE (PRP_COMPANY = 1) ORDER BY PRP_NAME)4.2. CPROP_VALUE

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved