Results 1 to 7 of 7
  1. #1
    alexsmith91 is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2023
    Posts
    17

    Question How to resolve #Name error?

    Hey,


    I have a continuous form that should populate the output from a SQL query.


    Code:
    Private Sub Form_Load()
    Dim A As New ADODB.Recordset
    Dim DC As New DataConnection
    
    
    Dim strSQL As String
    
    
    
    
    strSQL = "SELECT FULL_NAME as NAME, PHONE as DIAL, LOCATION as ADDRESS from table;"
             
             A.Open strSQL, DC.ConnectionProperties, adOpenKeyset, adLockOptimistic
             
             Set Me.Recordset = r
    
    
    End Sub
    The DC.ConnectionProperties is the connection string that is already defined and it working as expected, since I use the same connection for other queries as well.

    Below is the debugging that I have already performed and are producing the output as expected in the Intermediate window
    • SQL query is correct.
    • debug.print field
    • debug.print value
    • debug.print recordcount
    • Control source has not been changed and they are as-is.



    What other debugging that I can do to check to see the issue?

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Name is a reserved word (and a poor choice of Alias, Name of what?) so if you continue to use it try surrounding it with square brackets [Name]

    In addition to the above I've just re-read your post

    You aren't setting the recordset to your SQL.

    Edit2:

    Why bother with all the ADODB stuff?
    Just set the forms recordsource to the SQL, assuming the table is linked?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    alexsmith91 is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2023
    Posts
    17
    Thanks for your quick reply.

    1: I changed the reference of NAME to other text and it still doesnt populate. I also modified the control source to match the alias.

    2: Oh got it, I fixed that as well. Set Me.Recordset = A. But still doesnt populate the form

    3: the table is not linked. and I dont have that option to do it.

    Quote Originally Posted by Minty View Post
    Name is a reserved word (and a poor choice of Alias, Name of what?) so if you continue to use it try surrounding it with square brackets [Name]

    In addition to the above I've just re-read your post

    You aren't setting the recordset to your SQL.

    Edit2:

    Why bother with all the ADODB stuff?
    Just set the forms recordsource to the SQL, assuming the table is linked?

  4. #4
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Have you tried using

    Me.RecordSource = A

    I'm not sure setting the forms recordset has the same effect?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    alexsmith91 is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2023
    Posts
    17
    Got a Compile Error : Type mismatch error on that line you suggested.

    So the reason I had put set me.recordset=A is because, I have a button against each row and then once you click the button, it will take the Name, Dial, Address for that record and open a new form and populate information on that.

    Quote Originally Posted by Minty View Post
    Have you tried using

    Me.RecordSource = A

    I'm not sure setting the forms recordset has the same effect?

  6. #6
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Okay create a pass through query with the same SQL. Make sure you set the connection properties as per you existing connection string.
    Save it as pt_MyData
    Set the forms Recordsource to the query in the form, note it won't be editable.

    That will allow you to open the query and see that it is bringing in the correct data, and lets you mess about with the syntax easily if it's not quite right.

    Still not sure why you can't link to it if you can create a ADODB connection to it?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  7. #7
    alexsmith91 is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2023
    Posts
    17
    I did that.
    I also checked the query and it was populating the correct data with no issues on syntax.
    Now when I set the rs to query, it is now popultaing the table.
    Weird and strange.
    Thanks.

    Quote Originally Posted by Minty View Post
    Okay create a pass through query with the same SQL. Make sure you set the connection properties as per you existing connection string.
    Save it as pt_MyData
    Set the forms Recordsource to the query in the form, note it won't be editable.

    That will allow you to open the query and see that it is bringing in the correct data, and lets you mess about with the syntax easily if it's not quite right.

    Still not sure why you can't link to it if you can create a ADODB connection to it?

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

Similar Threads

  1. var() does not resolve type mismatch error
    By deguza in forum Queries
    Replies: 5
    Last Post: 04-28-2023, 11:43 AM
  2. Resolve Error regarding missing object dependency
    By drunyan0824 in forum Access
    Replies: 18
    Last Post: 04-13-2023, 09:52 AM
  3. Sort issue- how to resolve
    By stalk in forum Queries
    Replies: 2
    Last Post: 05-31-2019, 03:32 PM
  4. Need help to resolve - Error appears "Object Required"
    By awaiskazmi in forum Programming
    Replies: 4
    Last Post: 10-30-2017, 10:45 PM
  5. Replies: 2
    Last Post: 02-09-2017, 05:22 AM

Tags for this Thread

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