Results 1 to 2 of 2
  1. #1
    jeffhanner is offline Advanced Beginner
    Windows 10 Access 2019
    Join Date
    Sep 2022
    Location
    Lincolln, CA
    Posts
    40

    Using a integer variable in a where clause

    I am trying to use a variable, TempS, in the Where Clause. I keep getting error 2147217904 (80040e 10Y: - No Value given for one or more of the parameters (in the open statement).
    When I substitute the actual number, 5400 for TempS. Everything works fine, the record is located and the date and id are updated. Do I have to encapsulate the variable name some how? Also, I did check the value of the variable and it was 5400. Any suggestions?
    Thanks,
    Jeff
    UPDATE: I Changed "MSNumber = TempS" to "MSNumber = " & TempS and everything worked.


    Code:
    Sub LogDateEdited(CurrentshelterNumber)   ' Under construction
       Dim TempS As Integer
       TempS = [SNumber]
       
       If MsgBox("HAVE YOU UPDATED THE POINTS OF CONTACT? " & Chr(10) _
                  & "Note: YES will date stamp 'POCs Last Edited' with " _
                  & "today's date", vbYesNo + vbQuestion) = vbYes Then
                  
          Dim rs As ADODB.Recordset
          Set rs = New ADODB.Recordset
        
          rs.Open "SELECT * FROM tblLastModified WHERE " & _
            "MSNumber = TempS", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
          
    
    
    
    
       rs![MEditDate].Value = Date
       rs![MEditId] = TempVars!tempLoginName
    
    
           Debug.Print rs![MSNumber]
           Debug.Print rs![MEditDate]
           Debug.Print CurrentshelterNumber
       
       rs.Update
    
    
       rs.CLOSE
     
    
    
    
    
    
    
        End If
    
    
    End Sub

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    You need to concatenate the variable into the sql string
    "Msnumber=" & temps
    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. Replies: 3
    Last Post: 08-02-2021, 09:15 AM
  2. Replies: 7
    Last Post: 01-05-2019, 11:17 AM
  3. How to Set an Integer to Nothing
    By orcinus in forum Programming
    Replies: 4
    Last Post: 05-17-2011, 11:21 AM
  4. Adding column as INTEGER makes it a long integer?
    By luckycharms in forum Programming
    Replies: 2
    Last Post: 10-20-2010, 02:47 PM
  5. How to ADD integer (vba)
    By Computer202 in forum Programming
    Replies: 24
    Last Post: 03-13-2010, 08:50 AM

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