Results 1 to 3 of 3
  1. #1
    altotoe is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    4

    Angry Passage of parameters - Form Update

    Hi all.


    I have been looking around to solve my little issue, but I haven't been that lucky so far, so I decided to write a post. I know some VBA and did some simple programming. This one is beyond my capabilities, although it may seem the simplest thing to some of the readers.


    The DB I am working on concerns a terminology database (termbase) (Definition). The labels are in Italian, but I provide suitable English translation here.


    I have two tables in the DB: scheda (card) and domini (domains). Every single term belongs to at least one domain. Domains are indicated by a three-character code and one definition (DB relations here).


    Problem: as I input a new record (i.e. a new term), I want to assign it to the domain(s) it belongs to. For example: "aircraft" may belong to "air force" and "transportation".


    What I want to do is the following: when I click on the "Assegna dominio" (assign to domain) button in the "scheda" (term card) Form, the Domains Form opens up (screenshot).


    After I flagged what domains the term belongs to, I click on the "Assegna ed esci" button (Assign and Exit) (name of button in code is "aggiungi_domini").
    The sub goes through the entire Domains Form (it's about 200 records) and creates a string by appending flagged domains (screenshot). The string is then appended to the content of the [dominio] field (domain) in the "scheda" (term card) Form (that's where parameters are passed).


    Here's the code I have written so far:


    Code:
    Public Function aggiungi_domini_click(ByVal addme As String)
    Dim i As Integer, domstr, titolo As String
    
    
    i = 1
    domstr = ""
    titolo = "Domain"
    
    
    DoCmd.GoToRecord , "domini", acFirst            'go to record #1 in Domini form
    
    
    Do Until i = DCount("*", "domini")              'from beginning to end of table
      If add_flag = True Then                       ‘check if flag is set to APPEND
        If i = DCount("*", "domini") Then Exit Do   'if end of table, exit
        domstr = domstr & [codice_dominio] & " "    'else append domain
        add_flag = False                            'reset flag to NOT APPEND
        i = i + 1                                   'increment counter
        DoCmd.GoToRecord , "domini", acNext         'move to next record
            
      Else                                          'flag is set to NOT APPEND
        If i = DCount("*", "domini") Then Exit Do   'if end of table, exit
        i = i + 1                                   'increment counter
        DoCmd.GoToRecord , "domini", acNext         'go to next record
      End If
    Loop
    
    
    addme = domstr
    
    
    End Function
    
    
    
    
    Public Sub apri_domini(ByVal domstr As String)
    
    
      DoCmd.OpenForm "domini", acNormal
      
      With Forms("domini").Controls("aggiungi_domini")
        If .OnClick = "" Then
        .OnClick = "aggiungi_domini_click addme:=domstr"
        End If
      End With
    
    
    DoCmd.Close acForm, "domini", acSaveYes         'close the form
    
    
    End Sub
    
    
    
    
    Private Sub assegna_dominio_Click()
    
    
    apri_domini domstr:=dominio
    
    
    End Sub

    Probably (perhaps definitely) my code has some faults I cannot see, given my elementary knowledge.
    Can anyone help?
    Thank you in advance.

  2. #2
    DepricatedZero's Avatar
    DepricatedZero is offline Cthulhu Fhtagn!
    Windows 8 Access 2007
    Join Date
    Apr 2013
    Location
    Cincinnati
    Posts
    65
    If I'm understanding correctly, what you may want to do is set up a many-to-many (each term can have many domains, each domain can have many terms) relationship using a relationship table.

    Basically this would be a table that consists of the two primary keys (ID) of your two tables.

    Now when you want to add domains, you can use a multiselect listbox and a query to append the ID of your Term, and the ID of your Domain, to the relationship table (call it, say, TERMINE_DOMINI). THEN when you want to find what domains a term has, you only have to query for related entries in the TERMINE_DOMINI table to find which entries to pull from the DOMINI table - and you can build the query to pull from the DOMINI table WHERE the ID shares a related entry in the TERMINE_DOMINI table with the ID of your term.

    I really hope that makes sense, and anwsers your question. I may be misunderstanding what you're asking though, too - you want a way to add domains to terms as you create them, and to pull domains relative to your term without having to search each item?

  3. #3
    altotoe is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    4
    I haven't used this approach, but it serves the purpose well.
    I will try to implement it and get back to you and the forum as soon as possible to let you know if I succeeded.
    Thank you for the insight and the different perspective!

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

Similar Threads

  1. Getting parameters from a form
    By Abarency in forum Access
    Replies: 1
    Last Post: 10-19-2012, 11:38 PM
  2. Open form from parameters
    By funkygoorilla in forum Forms
    Replies: 5
    Last Post: 01-01-2012, 09:17 PM
  3. UPDATE function "too few parameters"
    By eww in forum Programming
    Replies: 5
    Last Post: 05-11-2011, 09:38 AM
  4. Passing parameters from a form
    By rfs in forum Forms
    Replies: 1
    Last Post: 03-15-2011, 12:25 AM
  5. Too Few Parameters - UPDATE SQL
    By jgelpi16 in forum Programming
    Replies: 3
    Last Post: 09-20-2010, 10:11 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