Results 1 to 3 of 3
  1. #1
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    DoCmd.Open form - Filtering (A2K SR1)

    A user is using the following code that accepts a value (StrInput) upon pressing a command button. They then want to use the StrInput value as a filter condition to then open a form. I tried to help but can't get it to work. Code is below. Any ideas? StrInput is always an integer.

    Dim StrMsg As String
    StrMsg = "What is the event id?"

    StrInput = InputBox(Prompt:=StrMsg)

    Dim stDocName As String
    Dim stLinkCriteria As String

    stLinkCriteria = "[EventID] = (' & StrInput & ')"


    stDocName = "Logbookfrm"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    End Sub

    Thanks
    Regards,

    Gary
    (It's been a while!)

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: DoCmd.Open form - Filtering (A2K SR1)

    It depends on the data type of the EventID field.

    If EventID is numeric (Byte, Integer, Long, Single, Double), the criteria variable should be set without single quotes and without parentheses:<pre>stLinkCriteria = "[EventID] = " & strInput</pre>

    If EventID is a string, the criteria variable should be set with quotes around it, but still without parentheses:<pre>stLinkCriteria = "[EventID] = " & Chr(34) & strInput & Chr(34)</pre>

    I have used Chr(34) here to insert quotes into the string; using single and double quotes works too but is not very readable.

  3. #3
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: DoCmd.Open form - Filtering (A2K SR1)

    Hans,

    Thanks, just what I was looking for. I couldn't get the syntax correct. <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Regards,

    Gary
    (It's been a while!)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •