Results 1 to 9 of 9
  1. #1
    boo is offline Novice
    Windows XP Access 2000
    Join Date
    Dec 2011
    Posts
    16

    Referring to a subform with VBA - database now added

    Hi



    I have a form, frm_Interpreter, which has a subform, frm_Language. I am trying to do a search from a form on which I have a combo box which lists all languages. Can anyone give me any pointers as to how to set out my VBA, so far I have the following attached to my cmdSearch Button, I know I need to define the frm_Interpreter and frm_Language in stLinkCriteria, but not sure how to correctly set this out.

    Private Sub cmdSearch_Click()
    On Error GoTo Err_cmdSearch_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frm_Interpreter"

    stLinkCriteria = "[Language]=" & "'" & Me![cboLanguage] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteriaExit_cmdSearch_Click:
    Exit Sub

    Err_cmdSearch_Click:
    MsgBox Err.Description
    Resume Exit_cmdSearch_Click

    End Sub

    Any help is greatly appreciated.
    Last edited by boo; 01-26-2012 at 12:14 PM.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848

  3. #3
    boo is offline Novice
    Windows XP Access 2000
    Join Date
    Dec 2011
    Posts
    16
    Thanks for that orange. I am still not sure what to do about the placement of the speech marks, should I go ahead like this -

    Private Sub cmdSearch_Click()
    On Error GoTo Err_cmdSearch_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frm_Interpreter"

    stLinkCriteria = "Forms!frm_Interpreter!frm_Language.Form!Language= " & "'" & Me![cboLanguage] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteriaExit_cmdSearch_Click:
    Exit Sub

    Err_cmdSearch_Click:
    MsgBox Err.Description
    Resume Exit_cmdSearch_Click

    End Sub

    thanks again, I'll go try this in the meantime.

  4. #4
    boo is offline Novice
    Windows XP Access 2000
    Join Date
    Dec 2011
    Posts
    16
    Hmm, I'm getting a compile error - label not defined

  5. #5
    boo is offline Novice
    Windows XP Access 2000
    Join Date
    Dec 2011
    Posts
    16
    Ah, I see that was a schoolboy error, too much cutting and pasting, should have read -


    Private Sub cmdSearch_Click()

    On Error GoTo Err_cmdSearch_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frm_Interpreter"

    stLinkCriteria = "Forms!frm_Interpreter!frm_InterpreterLanguage.For m!Language= " & "'" & Me![cboLanguage] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_cmdSearch_Click:
    Exit Sub

    Err_cmdSearch_Click:
    MsgBox Err.Description
    Resume Exit_cmdSearch_Click

    End Sub

    This is opening my frm_Interpreter, unfortunately the form is not displaying any of the information for the interpreter or the languages. Any suggestions?

    cheers

  6. #6
    boo is offline Novice
    Windows XP Access 2000
    Join Date
    Dec 2011
    Posts
    16
    If its any help the frm_Interpreter uses tbl_Interpreter as its record source. The subform, frm_Language, uses tbl_Language as its record source. The two tables are linked through a one to many relationship with InterpreterID as the PK in tbl_Interpreter and as a FK in tbl_Language.
    Last edited by boo; 01-26-2012 at 04:04 AM. Reason: typos galore

  7. #7
    boo is offline Novice
    Windows XP Access 2000
    Join Date
    Dec 2011
    Posts
    16
    Here is a copy of the part of the database I am having problems with. The intention is to use frm_SearchInterpreterLangList to select the language, which will then open frm_Interpreter where the Interpreters have that language.

    Thanks for any help.

  8. #8
    boo is offline Novice
    Windows XP Access 2000
    Join Date
    Dec 2011
    Posts
    16
    No one any ideas on this one? I'm stumped, cant figure it out.

  9. #9
    boo is offline Novice
    Windows XP Access 2000
    Join Date
    Dec 2011
    Posts
    16
    I found a way to solve my problem, its not ideal, but it works. I've had to take a copy of the frm_Interpreter and I've then made its record source a query to tbl_Interpreter & tbl_Language. As I say, its working, but means creating a few duplicate forms.

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

Similar Threads

  1. Referring to range in access
    By ped in forum Access
    Replies: 11
    Last Post: 08-10-2011, 04:22 PM
  2. Referring to another table for a text box
    By hawkins in forum Reports
    Replies: 5
    Last Post: 07-05-2011, 04:14 PM
  3. Replies: 2
    Last Post: 11-26-2010, 04:20 AM
  4. Referring to objects
    By stubbly in forum Programming
    Replies: 1
    Last Post: 10-14-2009, 09:36 AM
  5. Referring to fields in tab controls
    By AndrewAfresh in forum Forms
    Replies: 1
    Last Post: 06-03-2006, 05:10 PM

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