Results 1 to 4 of 4
  1. #1
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658

    VBA query with id as long integer problem

    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

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,945
    Correct, posts and threads can only be deleted by staff and moderators.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    numbers do not get quotes.
    DoCmd.OpenForm "frm_Au_EntityAka", , ,"EntityFid=" & Me.AID

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,980
    I believe it is not your data content, but what you are comparing it to?
    You made Me.Aid a string, but want to compare to long, hence datatype mismatch, so although it contains numbers in this case it must not be a string.
    Now if it was a telephone number, that would be different.

    To be on the safe side you could use Val()
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Calculating GPA with a long integer field
    By JoJoM in forum Queries
    Replies: 3
    Last Post: 01-06-2016, 02:58 PM
  2. how much text in long integer field?
    By accessmatt in forum Database Design
    Replies: 10
    Last Post: 12-22-2014, 03:54 PM
  3. AutoNumbered KeyField Long Integer duplicating value
    By wilpeter in forum Database Design
    Replies: 5
    Last Post: 10-01-2013, 09:52 PM
  4. Using DCount with Long integer
    By Dominaz in forum Access
    Replies: 5
    Last Post: 12-06-2011, 05:22 AM
  5. Adding column as INTEGER makes it a long integer?
    By luckycharms in forum Programming
    Replies: 2
    Last Post: 10-20-2010, 02:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums