accessisnew
Technical User
I want to run an SQL Select query in VBA to fetch one field in a row from the table using the primary key in the WHERE clause then perform an validation as to whether the Select found the record or didn't find the record.
Is there a simple If statement I can use to perform the validation?
CODE:
Private Sub Text34_Exit(Cancel As Integer)
On Error GoTo Err_Text34
Dim dbs As ADODB.Connection
Dim selectSQL As String
Set dbs = CurrentProject.Connection
selectSQL = "SELECT Tracking_Number
FROM t_CIOSP2_Awards WHERE" & _
"Tracking_Number=" & _
"'" & Text34 & "';"
dbs.Execute selectSQL
If (THIS IS WHERE I NEED HELP with record found) Then
msgbox "Record Exists"
Else
msgbox "Record not found"
End If
Exit_Text34:
Exit Sub
Err_Text34
MsgBox Err.Description
Resume Exit_Text34
End Sub
Is there a simple If statement I can use to perform the validation?
CODE:
Private Sub Text34_Exit(Cancel As Integer)
On Error GoTo Err_Text34
Dim dbs As ADODB.Connection
Dim selectSQL As String
Set dbs = CurrentProject.Connection
selectSQL = "SELECT Tracking_Number
FROM t_CIOSP2_Awards WHERE" & _
"Tracking_Number=" & _
"'" & Text34 & "';"
dbs.Execute selectSQL
If (THIS IS WHERE I NEED HELP with record found) Then
msgbox "Record Exists"
Else
msgbox "Record not found"
End If
Exit_Text34:
Exit Sub
Err_Text34
MsgBox Err.Description
Resume Exit_Text34
End Sub