andydinger
New member
- Local time
- Today, 12:59
- Joined
- Jun 21, 2022
- Messages
- 3
I think I have a problem that must have a simple solution but I can't find any online examples to help me.
Scenario:
I am using Access as the front end to an Azure SQL database. The tables are therefore an External Data Source connected via ODBC. I have a form which has an On Dbl Click Event Procedure in VBA:
So the question is how do I execute this query: "INSERT INTO dbo.Suppliers ([Part number],[Manufacturer part number]) VALUES (" & Number & ",'');" on the currently open database? If I use the Execute method as shown then how do I reference the external SQL database? I can't use the CurrentDb method as it thinks that Access is the back end rather than external SQL database. Or is there a better way to execute external queries?
Scenario:
I am using Access as the front end to an Azure SQL database. The tables are therefore an External Data Source connected via ODBC. I have a form which has an On Dbl Click Event Procedure in VBA:
Code:
Private Sub Number_DblClick(Cancel As Integer)
If IsNull(Number) Then Exit Sub ' If user double clicks an empty record then quit
If Not IsNull(DLookup("[Part number]", "dbo_Suppliers", "[Part number]='" & Number & "'")) Then
' If the Part number double clicked on exists in the Suppliers table then open the Supplier Entry form to edit it
DoCmd.OpenForm "Supplier Entry", , , "[Number]='" & Number & "'", acFormEdit, acDialog
Else
' If the Part number double clicked on does not exist in the Suppliers table then ask user whether to add it
message = "Part number " & Number & " has no supplier info" & vbNewLine & "Do you want to create one?"
If MsgBox(message, vbYesNo, "New supplier?") = vbYes Then
' If user wants to add Part number to Suppliers table then insert a new record and open the Supplier Entry form to edit it
' How do I reference the currently open database to execute this append query?
DATABASE.Execute " INSERT INTO dbo.Suppliers ([Part number],[Manufacturer part number]) VALUES (" & Number & ",'');"
DoCmd.OpenForm "Supplier Entry", , , "[Number]='" & Number & "'", acFormEdit, acDialog
End If
End If
End Sub