Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2013
    Posts
    2

    Unanswered: Two where conditions to open a form

    I am trying to open a form using two where conditions. I can get stLinkCriteria1 and stLinkCriteria2 to work seperately (the code commented out) but not together. What am I doing wrong?

    Private Sub Command55_Click()

    Dim stDocName As String
    Dim stLinkCriteria As String
    Dim stLinkCriteria1 As String
    Dim stLinkCriteria2 As String

    stDocName = "frmEdit_All_Billing_Data1"

    stLinkCriteria = "FYPeriod=" & "'" & [frmALL_Project_Billing Data].Form.[txt_Project_Data_FY_Period] & "'" And "User=" & "'" & Environ("USERNAME") & "'"
    'stLinkCriteria1 = "FYPeriod=" & "'" & [frmALL_Project_Billing Data].Form.[txt_Project_Data_FY_Period] & "'"
    'stLinkCriteria2 = "User=" & "'" & Environ("USERNAME") & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    End Sub

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    What happens when you try using stLinkCriteria? Do you receive an error message, are the results different from what you where expecting?
    Have a nice day!

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    can we see the actual stLinkCriteria?
    ie the value of the variable NOT the code
    Code:
    stLinkCriteria = "FYPeriod = '" & [frmALL_Project_Billing Data].Form.[txt_Project_Data_FY_Period] & "' And  User='"  & Environ("USERNAME") & "'"
    should work
    Im suspicious of the
    Code:
     & "'" And "User=" & "'" & Environ("USERNAME") & "'"
    in your original post
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Jun 2013
    Posts
    2

    Error

    The error I was getting was "Run Time error '13'"

    I actually figured it out. Code below.

    The values are stLinkCriteria1 = 2013-10 and stLinkCriteria2 = jsmith. The fiscal period and the username of the person using the db. Why suspicious?

    Still not sure why the And didn't work in the orginal code.


    Code:
    Private Sub Command55_Click()
    
    Dim stDocName As String
    Dim stLinkCriteria As String
    Dim stLinkCriteria1 As String
    Dim stLinkCriteria2 As String
    
    stDocName = "frmEdit_All_Billing_Data1"
    
    stLinkCriteria1 = "[FYPeriod]=" & "'" & [frmALL_Project_Billing Data].Form.[txt_Project_Data_FY_Period] & "'"
    stLinkCriteria2 = "User=" & "'" & Environ("USERNAME") & "'"
    stLinkCriteria = stLinkCriteria1 & " And " & stLinkCriteria2
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    
      
    End Sub

Tags for this Thread

Posting Permissions

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