Call Button on Another Form Issue (1 Viewer)

123dstreet

Registered User.
Local time
Today, 00:43
Joined
Apr 14, 2010
Messages
122
I have a form (form1) which will open another form (form2) and apply a filter using a filter button already on form 2. I have applied the following code which works properly for 2 of the 3 forms this needs to be done on:

The below line 'Call Forms.[RMA Data].Command40_Click' works for both BT200 and STB100, but returns an error for BT100 'Object doesn't support this property or method'.

I'm guessing there's a setting on the BT100 form preventing this filter from running, any ideas???

Code:
Private Sub Command99_Click()
On Error GoTo Err_Command99_Click

    Dim stDocName As String
    Dim stLinkCriteria As String
    Dim strRMA As String
    Dim strProduct As String
    Dim strSN As String
    
'set SN variable from Support log record
    If IsNull(Me.wstSN) = False Then strSN = Me.wstSN
    If IsNull(Me.wstSN) = True Then
    MsgBox "Nothing to show for this unit."
    Exit Sub
    End If
    
'determine product
strProduct = Me.Product

If strProduct = "BT100" Then GoTo BT100
If strProduct = "BT200" Then GoTo BT200
If strProduct = "STB100" Then GoTo STB100
Exit Sub

BT100:
    stDocName = "RMA Data"
    DoCmd.OpenForm stDocName
    'set search criteria and run filter command from RMA form
     Forms![RMA Data]![Text38] = strSN
    Call Forms.[RMA Data].Command40_Click
    DoCmd.GoToRecord , , acLast
Exit Sub

BT200:
    stDocName = "RMABT200form"
    DoCmd.OpenForm stDocName
    'set search criteria and run filter command from RMA form
    'Forms!RMABT200form![Text43] = strRMA
    'Call Forms.RMABT200form.Command45_Click
    'If IsNull(strSN) = False Then
    Forms!RMABT200form![Text38] = strSN
    Call Forms.RMABT200form.Command40_Click
    'End If
    DoCmd.GoToRecord , , acLast
Exit Sub

STB100:
    stDocName = "RMASTB100form"
    DoCmd.OpenForm stDocName
    'set search criteria and run filter command from RMA form
      Forms!RMASTB100form![Text38] = strSN
        Call Forms.RMASTB100form.Command40_Click
    DoCmd.GoToRecord , , acLast
Exit Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:43
Joined
May 7, 2009
Messages
16,421
did you also make Command40_Click event on form "RMA Data", Public?
 

123dstreet

Registered User.
Local time
Today, 00:43
Joined
Apr 14, 2010
Messages
122
Yes, I changed the Click events on these forms to Public:
The code for all 3 forms is basically identical. The below code runs fine when run from the RMA Data form.

Code:
Public Sub Command40_Click()
On Error GoTo ExitError
    '-- Find Serial Numbers starting with ---
    Me.Filter = "[Serial Number] Like" & "'" & Me.Text38 & "*" & "'"
    If IsNull([Text38]) = False Then Me.FilterOn = True Else Me.FilterOn = False
    SendKeys "+{Down}"
ExitError:
    Exit Sub
End Sub
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:43
Joined
Feb 19, 2002
Messages
36,352
I'm pretty sure that what you are doing is significantly more complex than should be necessary.
1. ALWAYS give your controls meaningful names. "Text38" is not acceptable. Next week, you won't know what Text38 is and no one examining your code could guess if his life depended on it.
2. The way you "filter" a form you are opening is to use the Where argument of the OpenForm method.

Just FYI,
Putting several different procedures into one, doesn't actually simplify anything. If you have different procedures for opening each of three forms, use three separate procedures rather than one with three separate sections of code.
 

123dstreet

Registered User.
Local time
Today, 00:43
Joined
Apr 14, 2010
Messages
122
Thanks Pat,
I'm definitely a hack.

Is it possible to use a Where argument to filter a Continuous form? I would definitely prefer to use this method I just didn't know if it would work.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:43
Joined
Feb 19, 2002
Messages
36,352
Continuous forms are no different from single view forms. You just see multiple records at once.
 

123dstreet

Registered User.
Local time
Today, 00:43
Joined
Apr 14, 2010
Messages
122
Okay I'll give this a try.
I'm still curious though why the identical Call function is working on 2 other forms no problem but returning an error on this form.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:43
Joined
Feb 19, 2002
Messages
36,352
Without the db, all we could do would be to guess.
 

123dstreet

Registered User.
Local time
Today, 00:43
Joined
Apr 14, 2010
Messages
122
Is this Where argument syntax correct?
strWhere = "Forms![RMA Data]![Serial Number] Like" & "'" & Me.wstSN & "*" & "'"
 

123dstreet

Registered User.
Local time
Today, 00:43
Joined
Apr 14, 2010
Messages
122
I've got it working with Where now, thanks for your help Pat!

Code:
BT100:
    stDocName = "RMA Data"
    strWhere = "[Serial Number]=" & strSN
    DoCmd.OpenForm stDocName, , , strWhere
    DoCmd.GoToRecord , , acLast
Exit Sub

BT200:
    stDocName = "RMABT200form"
    strWhere = "[SN]=" & strSN
    DoCmd.OpenForm stDocName, , , strWhere
    DoCmd.GoToRecord , , acLast
Exit Sub

STB100:
    stDocName = "RMASTB100form"
    strWhere = "[SN]=" & strSN
    DoCmd.OpenForm stDocName, , , strWhere
    DoCmd.GoToRecord , , acLast
Exit Sub
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:43
Joined
Feb 19, 2002
Messages
36,352
Glad you got it working:)
Not sure what the gotorecord is all about. You are using a where argument so don't you want to open to that record?

And again, instead of directing three buttons to one procedure where you need multiple If"s to now separate back into the three choices, all you have done is obfuscated the logic.
 

123dstreet

Registered User.
Local time
Today, 00:43
Joined
Apr 14, 2010
Messages
122
Hi Pat,
The gotorecord is because there could be several records displayed but the last one is where I want to land first.

There's only 1 button, 3 IF's, each IF has its own solution - how would you do that less obfuscated? Please share.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:43
Joined
Feb 19, 2002
Messages
36,352
I'm looking at the procedure out of context so I might not hit on the right solution. One thing you can do is to add a couple of fields to your product table so you don't have to hard code stuff. Then you can use hidden field values from the combo's RowSource where you choose your product. This gives you a little more flexibility and instead of requiring code changes, you might be able to just add a new row to your table with different values to control the criteria and the forms.

It is always a red flag when you have hard coded choices the way you do. Think about how Amazon would work if they had to hardcode the form and criteria fields to bring up information on each product.
 

123dstreet

Registered User.
Local time
Today, 00:43
Joined
Apr 14, 2010
Messages
122
Hi Pat,
Thanks for the input, I appreciate all the help I can get these days. Always learning something new!
 

Users who are viewing this thread

Top Bottom