Link to home
Start Free TrialLog in
Avatar of shieldsco
shieldscoFlag for United States of America

asked on

Drill Down on a Form

I using the code below to drill down from one form to another. It works if the match is one word however when the lookup is more than one word it does not find the value. For example if the lookup is "ISSO" the value is found...If the lookup is "System Owner" the value is not found. Any thoughts.

Dim strList As String
 strList = "('" & Replace(Me.Currently_With, " ", "','") & "')"
 If DCount("*", "UFMS Weakness Remediation Summary", "[Currently With] In " & strList) = 0 Then
      MsgBox "No related record found", vbExclamation, "UFMS"
      Exit Sub
  Else
 End If
 DoCmd.OpenForm "frm_Remediation Summary", , , "[Currently With] In " & strList
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

post the values displayed in "Me.Currently_With"

<.If the lookup is "System Owner" the value is not found>
in your replace statement, the space " " is being replaced, so  "System Owner"  becomes  "SystemOwner"
Avatar of shieldsco

ASKER

OFSP
O&M
System Owner
OpDiv
OCIO
I would prefer not to hard code the values
why are you using this line in your code

strList = "('" & Replace(Me.Currently_With, " ", "','") & "')"

is the control Me.Currently_With, list  multiple items?
what is the control Source of the cotrol Me.Currently_With?
Me.Currently_With is multiple items
and the control source is a query
post the query here.
SELECT [UFMS Weakness Remediation Summary].[Weakness Remediation Status] AS Status, [UFMS Weakness Remediation Summary].[Currently With], Count([UFMS Weakness Remediation Summary].ID) AS [Number]
FROM [UFMS Weakness Remediation Summary]
GROUP BY [UFMS Weakness Remediation Summary].[Weakness Remediation Status], [UFMS Weakness Remediation Summary].[Currently With];
Can the spaced be trimed in the query?
<Can the spaced be trimed in the query? >  YES, but i don't think it resolve your problem.

how are data entered in the field [Currently With] ?
Me.Currently_With is multiple items
When you build this string, why not build it correctly with commas and quotes rather than using spaces that you later have to replace with commas?  

Usually when building an IN() string people concatenate the value with the delimiters and then remove the final comma.

strIN = strIN & """" & Me.someitem & ""","

then at the end,

If strIN & "" <> "" Then
    strin = Left(StrIN, Len(StrIN) -1)
End If
it a list box
Dim strList As String


 'strList = "('" & Replace(Me.Currently_With, " ", "','") & "')"
 StrIN = StrIN & """" & Me.Currently_With & ""","

Pat - No related record found

 'If DCount("*", "UFMS Weakness Remediation Summary", "[Currently With] In " & strList) = 0 Then

 If StrIN & "" <> "" Then
     StrIN = Left(StrIN, Len(StrIN) - 1)
      MsgBox "No related record found", vbExclamation, "UFMS"
      Exit Sub
  Else
 End If
 DoCmd.OpenForm "frm_Remediation Summary", , , "[Currently With] In " & strList
Pat - No related record found

Dim strList As String


  'strList = "('" & Replace(Me.Currently_With, " ", "','") & "')"
  StrIN = StrIN & """" & Me.Currently_With & ""","

  'If DCount("*", "UFMS Weakness Remediation Summary", "[Currently With] In " & strList) = 0 Then

  If StrIN & "" <> "" Then
      StrIN = Left(StrIN, Len(StrIN) - 1)
       MsgBox "No related record found", vbExclamation, "UFMS"
       Exit Sub
   Else
  End If
  DoCmd.OpenForm "frm_Remediation Summary", , , "[Currently With] In " & strList
I'm confused.  Are you building a string of values or are you selecting a single value?  If you are selecting a single value then

DoCmd.OpenForm "frm_Remediation Summary", , , "[Currently With] = '" & Me.Currently_With  & "'"

is the simplest syntax.

You would only use IN() if you were actually building something that looked like:

'apple', 'orange', 'pear'

DoCmd.OpenForm "frm_Remediation Summary", , , "[Currently With] = 'orange'"
OR
DoCmd.OpenForm "frm_Remediation Summary", , , "[Currently With] In('apple', 'orange', 'pear')"
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Rey - Compile error - method or data member not found

.ItemsSelected.Count
what is the name of the listbox, check if it has underscore or no
Currently With... no underscore
change this line

With Me.[Currently_With]

with


With Me.[Currently With]
Change to Currently With and received the following error:

method or data member not found

 .ItemsSelected.Count