Results 1 to 12 of 12
  1. #1
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694

    Syntax Error Help with Recordset

    Can someone else put a pair of eyes on this? I've been programming for too long I think, and something obvious is missing, but can't put a finger on it..

    The following line is giving me a syntax error in expression:


    Code:
    rsStockIn.FindFirst ("[pID] = " & !pID & " AND [pExhausted] = 0")

    Here is part of the module that is relevant:
    Code:
    rsStockIn.MoveLast
    rsStockIn.MoveFirst
       rsStockOutTEMP.MoveLast
       rsStockOutTEMP.MoveFirst
    
          With rsStockOutTEMP
          
             Do Until .EOF
             
                While sItemRecorded = False
                
                   rsStockIn.MoveFirst 'PREP FOR FIND RECORD COMMAND
                
                   rsStockIn.FindFirst ("[pID] = " & !pID & " AND [pExhausted] = 0") 
          
    '''''MORE CODE'''''''
    
                Wend
                
                   sItemRecorded = False
                      .MoveNext
             Loop
          
          End With
    The !pID field is a LONG and Exhausted is a BOOLEAN. I ran on a test with a simple recordset with the exact same line of syntax replacing !pID with a LONG variable that was declared and it worked fine and found the record. What am I missing guys? Thanks for any help!

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I would try it without the parens or with them inside of the quotes.
    rsStockIn.FindFirst "([pID] = " & !pID & " AND [pExhausted] = 0)"
    ...or...
    rsStockIn.FindFirst "[pID] = " & !pID & " AND [pExhausted] = 0"

  3. #3
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by RuralGuy View Post
    I would try it without the parens or with them inside of the quotes.
    rsStockIn.FindFirst "([pID] = " & !pID & " AND [pExhausted] = 0)"
    ...or...
    rsStockIn.FindFirst "[pID] = " & !pID & " AND [pExhausted] = 0"
    Allen,

    I tried both of those and it still throws the error. Is there anything I could give you that would help you help me? The module is kinda long. - 250 lines

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Have you tried importing the db into a new db to eliminate a corruption issue?

  5. #5
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by RuralGuy View Post
    Have you tried importing the db into a new db to eliminate a corruption issue?
    is the best way to do that importing all at once or the one corrupted module by itself and then the rest of the obj's all at once? what have you done in the past?

    also,

    do you think copying the mod code to notepad, deleting the module out and then pasting it back to a new module would work?

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I would try all at once to start. If the problem follows then the import will probably not fix the problem regardless of how you do it. I don't know about the clipboard method by Export to Text file, delete and then Import from textfile should work.

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    A little further help:
    Application.SaveAsText(ObjectType AS acObjectType, ObjectName As String, FileName As String)

    LoadFromText is identical in its parameters. For example:

    Application.SaveAsText(acForm,"frmMyForm","H:\Clie ntX\frmMyForm.txt")

  8. #8
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by ajetrumpet View Post
    Code:
                 rsStockIn.FindFirst ("[pID] = " & !pID & " AND [pExhausted] = 0")

    "!pID" is how you refer to a field in a record source from a form.

    When you open a recordset in code, to refer to a field in the recordset, you need to you the ".Fields()" property.


    Try this:

    Code:
     rsStockIn.FindFirst ("[pID] = " & .Fields("pID") & " AND [pExhausted] = FALSE")

    ------------------------
    I use FALSE & TRUE instead of 0 (zero) & -1 in case MS ever decides to change the constants. (FYI: In Excel, FALSE = 0 and TRUE = +1.)
    ------------------------

  9. #9
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by ssanfu View Post
    When you open a recordset in code, to refer to a field in the recordset, you need to you the ".Fields()" property.
    To refer to the collection's INDEX yes, to the value in that field, no not necessary. There is more than one way. Sorry

    thanks for the input though. I will try the booleans. I haven't yet. still stuck with the longs.

  10. #10
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    OK,

    Have you tried this??

    Code:
    rsStockIn.MoveLast
    rsStockIn.MoveFirst
       rsStockOutTEMP.MoveLast
       rsStockOutTEMP.MoveFirst
     
         Dim Criteria as String
     
          With rsStockOutTEMP
     
             Do Until .EOF
     
                While sItemRecorded = False
                     Criteria = ""
    '   FindFirst starts from the the beginning of the recordset
    '             rsStockIn.MoveFirst 'PREP FOR FIND RECORD COMMAND
     
                     Criteria = "[pID] = " & !pID & " AND [pExhausted] = FALSE"
                     MsgBox Criteria     ' is the string what you expected???
     
                     rsStockIn.FindFirst (Criteria) 
     
    '''''MORE CODE'''''''
                Wend
     
                   sItemRecorded = False
                      .MoveNext
             Loop
     
          End With

    .

  11. #11
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    RG,

    the module was corrupt. I put the func. in a new module and took out all the args. the code ran fine. not sure why, but it was the last thing I tried.

    thanks for the help

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Any time, glad to help.

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

Similar Threads

  1. SQL INSERT INTO Date Syntax Error
    By tuna in forum Programming
    Replies: 5
    Last Post: 08-10-2010, 06:17 AM
  2. Syntax error
    By smikkelsen in forum Access
    Replies: 6
    Last Post: 04-28-2010, 09:38 AM
  3. Syntax Error
    By KLynch0803 in forum Programming
    Replies: 11
    Last Post: 02-04-2010, 01:45 AM
  4. sql syntax error
    By SMAlvarez in forum Access
    Replies: 1
    Last Post: 03-12-2009, 09:43 PM
  5. Syntax Error In Insert Into Statement
    By frankvfox in forum Queries
    Replies: 1
    Last Post: 09-09-2008, 12:35 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