J
JohnB762
Hello to everybody,
I am trying to update a form with an update query by a clic on a button and
get the number of record updated, passing the parameter from a form named
"Esercizi_pubblici_Update".
In this form there are:
- Old text box "Attivita" to a new Combo called "CboAttività"
- Old text box "Esercizio" to a new Combo called "CboEsercizio"
The table I would like to update is "Esercizi_pubblici" with his [Attività] &
[Tipologia_Esercizio] fileds.
The SQL of the update query is
UPDATE Esercizi_pubblici SET Esercizi_pubblici.Attività = [Forms]!
[Esercizi_pubblici_Update]![CboAttività], Esercizi_pubblici.
Tipologia_Esercizio = [Forms]![Esercizi_pubblici_Update]![CboEsercizio]
WHERE (((Esercizi_pubblici.Attività)=[Forms]![Esercizi_pubblici_Update]!
[Attivita]) AND ((Esercizi_pubblici.Tipologia_Esercizio)=[Forms]!
[Esercizi_pubblici_Update]![Esercizio]));
and if I run the query alone everything is fine.
But when I tried via VBA doesn't work at all.
The code that I am trying, run always with a syntax error message and since
my knowledge with VBA/SQL is limited I kindly aks help.
Many thanks and Kind Regards
John
Private Sub Update_Click()
On Error GoTo Err_Update_Click
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
Dim strOffice As String
Dim strOffice1 As String
Set db = CurrentDb
Set qdf = db.QueryDefs("Esercizi_pubblici_Update")
strOffice = "='" & Me.CboAttività.Value & "' "
strOffice1 = "='" & Me.CboEsercizio.Value & "' "
strSQL = "UPDATE Esercizi_pubblici.*" & _
"SET Esercizi_pubblici.[Attività]= strOffice, Esercizi_pubblici.
[Tipologia_Esercizio]=strOffice1" & _
"WHERE Esercizi_pubblici.[Attività] = Esercizi_pubblici.[Attivita]
" & _
"And Esercizi_pubblici.[Tipologia.Esercizio]= Esercizi_publici.
[Esercizio]"
qdf.SQL = strSQL
MsgBox "You updated " & qdf.RecordsAffected & " records", vbOKOnly,
"Pubblici Esercizi"
Set qdf = Nothing
Set db = Nothing
End Sub
I am trying to update a form with an update query by a clic on a button and
get the number of record updated, passing the parameter from a form named
"Esercizi_pubblici_Update".
In this form there are:
- Old text box "Attivita" to a new Combo called "CboAttività"
- Old text box "Esercizio" to a new Combo called "CboEsercizio"
The table I would like to update is "Esercizi_pubblici" with his [Attività] &
[Tipologia_Esercizio] fileds.
The SQL of the update query is
UPDATE Esercizi_pubblici SET Esercizi_pubblici.Attività = [Forms]!
[Esercizi_pubblici_Update]![CboAttività], Esercizi_pubblici.
Tipologia_Esercizio = [Forms]![Esercizi_pubblici_Update]![CboEsercizio]
WHERE (((Esercizi_pubblici.Attività)=[Forms]![Esercizi_pubblici_Update]!
[Attivita]) AND ((Esercizi_pubblici.Tipologia_Esercizio)=[Forms]!
[Esercizi_pubblici_Update]![Esercizio]));
and if I run the query alone everything is fine.
But when I tried via VBA doesn't work at all.
The code that I am trying, run always with a syntax error message and since
my knowledge with VBA/SQL is limited I kindly aks help.
Many thanks and Kind Regards
John
Private Sub Update_Click()
On Error GoTo Err_Update_Click
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
Dim strOffice As String
Dim strOffice1 As String
Set db = CurrentDb
Set qdf = db.QueryDefs("Esercizi_pubblici_Update")
strOffice = "='" & Me.CboAttività.Value & "' "
strOffice1 = "='" & Me.CboEsercizio.Value & "' "
strSQL = "UPDATE Esercizi_pubblici.*" & _
"SET Esercizi_pubblici.[Attività]= strOffice, Esercizi_pubblici.
[Tipologia_Esercizio]=strOffice1" & _
"WHERE Esercizi_pubblici.[Attività] = Esercizi_pubblici.[Attivita]
" & _
"And Esercizi_pubblici.[Tipologia.Esercizio]= Esercizi_publici.
[Esercizio]"
qdf.SQL = strSQL
MsgBox "You updated " & qdf.RecordsAffected & " records", vbOKOnly,
"Pubblici Esercizi"
Set qdf = Nothing
Set db = Nothing
End Sub