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.