Note: I figured it out. Need to remove the single quotes from around RecId in the qryToDo
(Still don't know how to delete a post, not an option that I can see)
I'm tackling my first VBA SQL with an AutoNumber id.
I can't tell what SQL is expecting.
One form is calling another through a command button with this:
Code:
Private Sub cmd_AkaForm_Click()
DoCmd.OpenForm "frm_Au_EntityAka", , , "EntityFid=" & Me.AID, , , Me.AID
Me.AID is the primary key, AutoNumber in the Entity table
On open the second form is doing this:
Code:
Private Sub Form_Open(Cancel As Integer)
Dim RecId As String
Dim db As DAO.Database: Dim rs As DAO.Recordset: Dim qryToDo As String
On Error GoTo ErrCd
Set db = CurrentDb
RecId = OpenArgs 'passed from frm_Au_Entity, contains Entity.AID; could be parsed, that's why separate variable
If RecId = "" Then
Cancel = True
Else
Stop
qryToDo = "SELECT * FROM tbl_Au_Entity WHERE AID = '" & RecId & "'"
Set rs = db.OpenRecordset(qryToDo, dbOpenSnapshot)
...
I've only done this kind of SQL statement with strings before for the WHERE in the SQL
As it's written, it fails on the last line (Set rs =...)
with err= 3464, error= Data type mismatch in criteria expression.
Checking the value of qryToDo shows this (which seems correct to me):
?qryToDo
SELECT * FROM tbl_Au_Entity WHERE AID = '-847198458'
I'm guessing it's having problems because the RecId is for a field that has an AutoNumber-Long integer data type (random) or because it is a negative number.
I've tried Clng() to no avail.
What is SQL expecting ,that I'm doing wrong for the Recid?
Thanks