afterUpdate Combo Event Help

chrisguk

Registered User.
Local time
Today, 09:04
Joined
Mar 9, 2011
Messages
148
Hi all,

I am trying to create an after update event using a combo box but with the following code it returns a runtime error 2494 Action or method requires a form name argument.

Ideally I would love for it to open a subform based on the value but I dont know how to do that. Heres the code, any ideas whats wrong:

Code:
Private Sub cboUtilityCategoryName_AfterUpdate()
Dim cboVal As String
Dim stDocName As String
Dim stLinkCriteria As String

stLinkCriteria = "[fkAccountID]=" & Me![AccountID]

cboVal = Me.cboUtilityCategoryName.Value

Select Case cboVal
Case "Electric"
    stDocName = "frmSitesMeterPointsMPAN"
Case "Red"
    stDocName = "Red Form"
Case "Green"
    stDocName = "Green Form"
End Select

DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub
 
What is the nature of the data being held in the bound column of cboUtilityCategoryName?
 
What is the nature of the data being held in the bound column of cboUtilityCategoryName?

Hi John,

Firstly apologies because my code was incomplete thus making it slightly ambiguous. I has pasted the correct code below. Essentially what I am looking for is a particular subform which has related data to the selected value in the combo box to appear. I already have the nomrlised tables setup to compile these subforms:

Code:
Private Sub cboUtilityCategoryName_AfterUpdate() Dim cboVal As String Dim stDocName As String Dim stLinkCriteria As String  stLinkCriteria = "[fkAccountID]=" & Me![pkAccountID]  cboVal = Me.cboUtilityCategoryName.Value  Select Case cboVal Case "Electric"     stDocName = "frmSitesMeterPointsMPAN" Case "Gas"     stDocName = "frmSitesMeterPointsMNumber " Case "Water"     stDocName = "frmSitesMeterPointsWater " End Select  DoCmd.OpenForm stDocName, , , stLinkCriteria End Sub
 
Code:
Private Sub cboUtilityCategoryName_AfterUpdate() 
Dim cboVal As String
Dim stDocName As String 
Dim stLinkCriteria As String 
 
stLinkCriteria = "[fkAccountID][COLOR=red]="[/COLOR] & Me![pkAccountID]  
cboVal = Me.cboUtilityCategoryName.Value 
 
Select Case cboVal 
Case "Electric"     
stDocName = "frmSitesMeterPointsMPAN" 
Case "Gas"     
stDocName = "frmSitesMeterPointsMNumber " 
Case "Water"     
stDocName = "frmSitesMeterPointsWater " 
End Select  
 
DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub

hi, this might be the problem. instead of this:
Code:
stLinkCriteria = "[fkAccountID]=" & Me![pkAccountID]

you need a space, so here..
Code:
stLinkCriteria = "[fkAccountID][COLOR=deepskyblue] = "[/COLOR] & Me![pkAccountID]

your form names also, if there's no space at the end, u should remove it.
 

Users who are viewing this thread

Back
Top Bottom