Results 1 to 4 of 4
  1. #1
    prendergi is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2013
    Posts
    2

    Openform with two criteria

    Hi All!



    I am new to writing VBA code. So new that this is my first time writing anything. I have been able to find information on what I am trying to do but I get to a point and I have no clue what I need to write next.

    So this is what I am trying to do: I have a form (CompanyF) that contains a text box called CompanyID, a text box called Company and an unbound listbox (companyloans) in which the row source is from a query. Companyloans contains the information of the Company's loan (amount, date started, type). When I double click on the Company's loan info I open another form (LoanF) that shows me their loan information (like loan id, interest rate, there are some subforms with loan schedule and such). If each company only had one loan it wouldn't be a problem but there are a few company's that have more than one loan. The code that I put in there will open the LoanF form but it won't take me to that specific loan. It will allow me to look at all the company's loans but I will have to use the arrows to move to each loan and I would rather double click on the loan info and go straight to that record.

    I found and used the following code to get to that point:

    Private Sub companyloans_DblClick(Cancel As Integer)
    If Not Me.NewRecord Then
    DoCmd.OpenForm "LoanF", _
    WhereCondition:="CompanyID=" & Me.CompanyID
    End If
    End Sub

    The row source for the listbox is a query and is as follows:

    SELECT LoansForCurrentCompanyQ.LoanID, LoansForCurrentCompanyQ.CompanyID, LoansForCurrentCompanyQ.LoanAmount, LoansForCurrentCompanyQ.StartDate, LoansForCurrentCompanyQ.Description
    FROM LoansForCurrentCompanyQ;

    I understand I told it just show the loan records for that CompanyID but I don't know how to tell it to go to the LoanID for the loan I want to look at.

    I would very much appreciate any guidance!! My books and research are just confusing me more.

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    If I understand correctly, you double click the list box to open the form "LoanF".

    I open another form (LoanF) that shows me their loan information (like loan id, interest rate,
    Try this:
    Code:
    Private Sub companyloans_DblClick(Cancel As Integer)
        If Not Me.NewRecord Then
            DoCmd.OpenForm "LoanF", WhereCondition:="CompanyID = " & Me.CompanyID & "AND LoanID = " & Me.companyloans
        End If
    End Sub

  3. #3
    prendergi is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2013
    Posts
    2
    Steve -
    You understood correctly and Thank you! It worked. I had put that in before and it would give me errors because the quotes were in the wrong place. I got them in the right place but it would take me to a new record. I don't even know enough to know if something is right or just off a little. After seeing your code and the research I was doing earlier, everything just clicked. I did have to before but had the wrong bound column. Thank you, thank you for helping put everything in place!

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Happy to help...

Please reply to this thread with any new information or opinions.

Similar Threads

  1. OpenForm to specific tab
    By rivereridanus in forum Access
    Replies: 1
    Last Post: 06-28-2012, 07:32 PM
  2. What actually happens at docmd.openform
    By Beorn in forum Programming
    Replies: 4
    Last Post: 01-05-2011, 02:19 PM
  3. Getting to a tab on openform
    By Swarland in forum Programming
    Replies: 5
    Last Post: 12-12-2010, 11:22 AM
  4. OpenForm macro
    By tguckien in forum Forms
    Replies: 3
    Last Post: 07-06-2010, 09:12 AM
  5. OpenForm Action and Arguments
    By nkenney in forum Forms
    Replies: 9
    Last Post: 04-05-2009, 09:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums