I am working on an infopath form using MS Access as the database.
On the form, I want to check emails for duplicates and I am trying to do this by running an SQL query from within the following VB code.
Public Sub CTRL125_7_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
Dim myAdoConnection As AdoQueryConnection = _
DirectCast(Me.DataConnections("Mainconnection"), AdoQueryConnection)
Dim mynav As XPathNavigator = _
CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/d:Candidate_Tracking_Database/@Email", NamespaceManager)
Dim email As String
email = mynav.InnerXml
myAdoConnection.Command = _
"select [Email] from [Candidate_Tracking_Database] where [Email] =" + email
myAdoConnection.Execute()
End Sub
I want to continue this with an If, then, else statement to prompt if the duplicate is found. However, I get the following error when I try to execute the code:
System.Net.WebException was unhandled by user code
Message="The query method on the Document object failed.
Operation aborted"
What am I doing wrong? Thanks in anticipation of an answer.
Notes:
I have Adapted the code from - http://msdn.microsoft.com/en-us/library/microsoft.office.infopath.adoqueryconnection.command.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
Elements in the Code are:
Mainconnection = connection name
"/dfs:myFields/dfs:dataFields/d:Candidate_Tracking_Database/@Email" = Xpath of the input text box
[Email] = Field name in the [Candidate_Tracking_Database] table
Complete Error is:
System.Net.WebException was unhandled by user code
Message="The query method on the Document object failed.
Operation aborted
"
Source="Microsoft.Office.InfoPath.Client.Internal.Host"
StackTrace:
at Microsoft.Office.InfoPath.Internal.MomExceptionHelper.ExecuteDataConnectionAction(OMCall d)
at Microsoft.Office.InfoPath.Internal.AdoQueryConnectionHost.Execute()
at Candidate_Registration.FormCode.CTRL125_7_Clicked(Object sender, ClickedEventArgs e) in C:\Infopath\InfoPath Projects\Candidate Registration\FormCode.vb:line 300
at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)
Try this:
myAdoConnection.Command = _
"select [Email] from [Candidate_Tracking_Database] where [Email] =" & email
or this:
myAdoConnection.Command = _
"select [Email] from [Candidate_Tracking_Database] where [Email] ='" & email & "'"