Microsoft 365 and Office | Access | For business | Windows
A family of Microsoft relational database management systems designed for ease of use.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Can someone please help me understand why this doesn't work and what the best fix is please? Thank You!
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
DAO operates at the database level, no at the Access interface level. So it doesn't "know" anything about Access forms and controls. Try this:
Private Sub Command2_Click()
Dim sql As String
Dim dbs As DAO.Database
sql = "INSERT INTO [TargetTable] (CompanyName, ParentRefFullName, [Name], JobDesc) " & _
"VALUES ('" & Forms!Form1!Text1 & "', " & _
"'" & Forms!Form1!Text1 & ":" & Forms!Form1!Combo1 & "', " & _
"'" & Forms!Form1!Text2 & "', " & _
"'" & Forms!Form1!Text3 & "')"
Set dbs = CurrentDb
dbs.Execute sql, dbFailOnError
End Sub
Instead of embedding the form references in the sql, it concatenates them at runtime.