Salve a tutti, sto creando un database in access e mi ritrovo con un problema, premetto che sono alle prime armi.
Ho una maschera di input nella quale ho la possibilità di scrivere dei valori (tramite casella combinata oppure campo text), nel momento in cui clicco sul pulsante cerca, deve fare una query per prendere dei campi che a me servono in visualizzazione nella maschera 2. Il problema è che non riesco ad impostare il campo di tabella. La mia funzione è così composta
Private Sub Cerca_Click()
On Error GoTo Err_Cerca_Click
' campi da considerare per la creazione della select
Dim sSql As String
Dim sWhere As String
Dim stDocName As String
'Questa procedura stabilisce una connessione
'con il database corrente con le 2 righe sotto riportate
Dim conn As ADODB.Connection
'Crea un nuovo Recordset
Dim rst As ADODB.Recordset
'Crea l'oggetto di connessione
Set conn = CurrentProject.Connection
'Crea un nuovo Recordset
Set rst = New ADODB.Recordset
'creo i campi di appoggio per le condizioni in tabella
Dim campo_1 As String
Dim campo_2 As String
Dim campo_3 As String
Dim campo_4 As String
Dim campo_5 As String
Dim campo_6 As String
Dim campo_5 As String
Dim campo_8 As Integer
'inizializzo i campi di appoggio
campo_1= ""
campo_2 = ""
campo_3 = ""
campo_4 = ""
campo_5 = ""
campo_6 = ""
campo_7 = ""
campo_8 = 0
'se i campi della maschera di input sono valorizzati imposto il loro valore nei campi di appogigo
If Me.campo_1<> "" Then campo_1= Me.campo_1
If Me.campo_2<> "" Then campo_2= Me.campo_2
If Me.campo_3<> "" Then campo_3= Me.campo_3
If Me.campo_4<> "" Then campo_4= Me.campo_4
If Me.campo_5<> "" Then campo_5= Me.campo_5
If Me.campo_6<> "" Then campo_6= Me.campo_6
If Me.campo_7<> "" Then campo_7= Me.campo_7
If Me.campo_8 > 0 Then campo_8= Me.campo_8
'valorizzo la select
sSql = ""
sSql = sSql & "SELECT "
sSql = sSql & "tabella1.campo_1, "
sSql = sSql & "tabella1.campo_2, "
sSql = sSql & "tabella2.campo_3, "
sSql = sSql & "tabella2.campo_4, "
sSql = sSql & "tabella3.campo_5, "
sSql = sSql & "tabella3.campo_6, "
sSql = sSql & "tabella4.campo_7, "
sSql = sSql & "tabella4.campo_8 "
sSql = sSql & "FROM "
sSql = sSql & "tabella1, "
sSql = sSql & "tabella2, "
sSql = sSql & "tabella3, "
sSql = sSql & "tabella4"
'valorizzo la condizione della select
sWhere = ""
If campo_1<> "" Then
sWhere = sWhere & " tabella1.campo_1 LIKE '*" & campo_1& "*'"
End If
If campo_2<> "" Then
sWhere = sWhere & " tabella1.campo_2 LIKE '*" & campo_2& "*'"
End If
If campo_3<> "" Then
sWhere = sWhere & " tabella2.campo_3 LIKE '*" & campo_3& "*'"
End If
If campo_4<> "" Then
sWhere = sWhere & " tabella_2.campo4 LIKE '*" & campo_4& "*'"
End If
If campo_5<> "" Then
sWhere = sWhere & " tabella3.campo_5 LIKE '*" & campo_5& "*'"
End If
If campo_6<> "" Then
sWhere = sWhere & " tabella3.campo_6 LIKE '*" & campo_6& "*'"
End If
If campo_7<> "" Then
sWhere = sWhere & " tabella4.campo_7 LIKE '*" & campo_7& "*'"
End If
If campo_8 > = 0 Then
sWhere = sWhere & " tabella4.campo_8 = campo_8 "
End If
If sWhere <> "" Then
sSql = sSql & " WHERE " & sWhere
End If
' Apre la tabella o la query
rst.Open sSql, conn
If rst.EOF = True Then
stDocName = "maschera_input" ' se non trova valori rstare nella stessa maschera
MsgBox "non esisono dati inseriti in tabella con queste condizioni"
End If
If rst.EOF = False Then
stDocName = "maschera_output"
Forms!maschera_output!campo_1.Text = rst("tabella11campo_1").Value
End If
rst.Close: Set rst = Nothing
conn.Close: Set conn = Nothing
Dim stLinkCriteria As String
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_Cerca_Click:
Exit Sub
Err_Cerca_Click:
MsgBox Err.Description
Resume Exit_Cerca_Click
End Sub
Continua a darmi questo errore "Impossibile trovare l'oggetto nell'insieme corrispondente al nome o al numero richiesto".
Cosa sbaglio?
Grazie a tutti per l'aiuto