Only a slight change, but try this:
-
Private Sub Form_open(Cancel As Integer)
-
-
Dim rs As DAO.Recordset
-
Set rs = DBEngine(0)(0).OpenRecordset("SELECT Variant1 FROM Projects WHERE EngineeringID = " & EngineeringID.Value & ";")
-
If Not rs.EOF Then
-
Dim var1 As String: var1 = rs!Variant1
-
Forms!Engineering!Variant1 = rs!Variant1
-
DoCmd.RunSQL ("UPDATE Projects SET Variant1 = '" & rs!Variant1 & "' WHERE Variant1 = '" & var1 & "';")
-
End If
-
End Sub
-
MAKE SURE: Variant1 is actually a field in this table. If you still get an error, tell me what error and which line.
Hope this helps.
Hello again,
Its still not working :(
Just to confirm:
which primary key should i enter in the code? the one from the table where the user inputs the text or the one from the table where the text its going to be displayed???
im entering this code into the ENGINEERING form which is where the textbox is supposed to DISPLAY the text entered on form PROJECTS
names of BOTH textboxes are VARIANT1 both bounded to VARIANT1 field on their corresponding table.
I tried both ways and the errors are the following:
OPTION 1
1 Private Sub Form_open(Cancel As Integer)
2 Dim rs As DAO.Recordset
3 Set rs = DBEngine(0)(0).OpenRecordset("SELECT Variant1 FROM Projects WHERE EngineeringID = " & EngineeringID.Value & ";")
4 If Not rs.EOF Then
5 Dim var1 As String: var1 = rs!Variant1
6 Forms!Engineering!Variant1 = rs!Variant1
7 DoCmd.RunSQL ("UPDATE Projects SET Variant1 = '" & rs!Variant1 & "' WHERE Variant1 = '" & var1 & "';")
8 End If
9 End Sub
With ENGINEERINGID (where the text should be displayed) the error is: '3061' "too few parameters. Expected 1" with line #3 highlighted
OPTION 2
1 Private Sub Form_open(Cancel As Integer)
2 Dim rs As DAO.Recordset
3 Set rs = DBEngine(0)(0).OpenRecordset("SELECT Variant1 FROM Projects WHERE ProjectID = " & ProjectID.Value & ";")
4 If Not rs.EOF Then
5 Dim var1 As String: var1 = rs!Variant1
6 Forms!Engineering!Variant1 = rs!Variant1
7 DoCmd.RunSQL ("UPDATE Projects SET Variant1 = '" & rs!Variant1 & "' WHERE Variant1 = '" & var1 & "';")
8 End If
9 End Sub
with PROJECTID (table where the user enters the text) the error is: '424' "object required" with the same line (#3) highlighted
thanks again