Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using variable as criteria in select statement in vba

Status
Not open for further replies.

belovedcej

Programmer
Nov 16, 2005
358
US
Following gives me an error at Call_Attorney_ID. It is a variable that has been declared earlier in the sub.

Is there another way I should not it since it is a variable and not a column in the sql statement?


Dim rst2 As ADODB.Recordset
Set rst2 = New ADODB.Recordset
rst2.ActiveConnection = CurrentProject.Connection
rst2.Open "SELECT Deleted_B FROM dbo.MED_Attorneys_T WHERE Attorney_ID = Call_Attorney_ID"


If "rst2" = "0" Then
MsgBox "Deletion failed. Record in use.", vbOKOnly

Else

Me.Requery
MsgBox "Deletion has been completed", vbOKOnly
End If
 
That seems to work - in debug mode I can see that it is pulling in the variable. Thanks!

However, now it always runs on the "Else" of the statement. Somehow rst2 does not equal 0, even though I know it does.
 
Got it!!

I changed the IF to rst!fieldname = 0


Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top