Page 3 of 4 FirstFirst 1234 LastLast
Results 31 to 45 of 50
  1. #31
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Did you add back this line?

    Code:
    Set DAO = OpenDatabase("W:\RCO\Databases\SQL_RCO_Database.accdb")

    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  2. #32
    Brian62 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2009
    Posts
    147
    Thanks, I got that part of the script to work along with the refresh command button. Now on my "Add Record", in the VBA script, it is highlighting .AddNew as indicated in the jpg. It is with Run-Time error 91: Object variable or With block variable not set.
    Click image for larger version. 

Name:	vba2.jpg 
Views:	3 
Size:	62.8 KB 
ID:	8288
    Private Sub CmdAdd_Click()
    Dim strsql As String
    Dim DAO As DAO.Database
    Dim RS As DAO.Recordset
    Dim LngCnt As Long

    LngCnt = 0

    strsql = "SELECT * FROM dbo_TblRDStudyAuditDocument WHERE ID_D = '" & Me.ID_D & "'"
    Debug.Print strsql
    Set DAO = OpenDatabase("W:\RCO\Databases\SQL_RCO_Database.ac cdb")
    LngCnt = 0

    With RS
    If LngCnt > 0 Then
    .MoveFirst
    .Index = "PK_TblRDStudyAuditDocument"
    .MoveLast
    ID_D = .Fields(0) + 1
    .AddNew
    .Fields(0) = ID_D
    .Fields(1) = Studyid
    .Fields(2) = AuditDate
    .Fields(3) = TxtSectionName
    .Fields(4) = DocName
    .Fields(5) = Comments
    .Update
    Else
    .AddNew (Highlighted in Yellow)
    .Fields(0) = 1
    .Fields(1) = Studyid
    .Fields(2) = AuditDate
    .Fields(3) = TxtSectionName
    .Fields(4) = DocName
    .Fields(5) = Comments
    .Update
    ID_D = 1

    End If
    .Close

    End With

    Set DAO = Nothing

    End Sub

  3. #33
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Now you've taken out the line setting the recordset.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #34
    Brian62 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2009
    Posts
    147
    I'm not sure what recoprdset I am missing. I compared it to the one we fixed earlier and I can't find anything missing.

  5. #35
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Seriously?

    Set RS = DAO.OpenRecordset(strsql, dbOpenDynaset, dbSeeChanges)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #36
    Brian62 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2009
    Posts
    147
    I added the script and it still gives me the same error. Yes seriously..... I'm not a VBA or SQL expert, that's why I come to you guys. You guys have been life savers.

    Private Sub CmdAdd_Click()
    Dim strsql As String
    Dim DAO As DAO.Database
    Dim RS As DAO.Recordset
    Dim LngCnt As Long

    LngCnt = 0

    strsql = "SELECT * FROM dbo_TblRDStudyAuditDocument WHERE ID_D = '" & Me.ID_D & "'"
    Set DAO = OpenDatabase("W:\RCO\Databases\SQL_RCO_Database.ac cdb")
    Set RS = DAO.OpenRecordset(strsql, dbOpenDynaset, dbSeeChanges)

    LngCnt = 0

    With RS
    If LngCnt > 0 Then
    .MoveFirst
    .Index = "PK_TblRDStudyAuditDocument"
    .MoveLast
    ID_D = .Fields(0) + 1
    .AddNew
    .Fields(0) = ID_D
    .Fields(1) = Studyid
    .Fields(2) = AuditDate
    .Fields(3) = TxtSectionName
    .Fields(4) = DocName
    .Fields(5) = Comments
    .Update
    Else
    .AddNew
    .Fields(0) = 1
    .Fields(1) = Studyid
    .Fields(2) = AuditDate
    .Fields(3) = TxtSectionName
    .Fields(4) = DocName
    .Fields(5) = Comments
    .Update
    ID_D = 1

    End If
    .Close

    End With

    Set DAO = Nothing

    End Sub

  7. #37
    Brian62 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2009
    Posts
    147
    When I reran the script, it doesn't like the new addition.

  8. #38
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You're still getting the 91 error on the AddNew? In case it's that variable name, try

    Code:
    Dim strsql As String
        Dim db As DAO.Database
        Dim RS As DAO.Recordset
        Dim LngCnt As Long
        
        LngCnt = 0
        
        strsql = "SELECT * FROM dbo_TblRDStudyAuditDocument  WHERE ID_D = '" & Me.ID_D & "'"
        Set db = OpenDatabase("W:\RCO\Databases\SQL_RCO_Database.accdb")
        Set RS = db.OpenRecordset(strsql, dbOpenDynaset, dbSeeChanges)


    It would be really helpful if you could post a sample of the db.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #39
    Brian62 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2009
    Posts
    147
    I made the change as you requested but still have an error on the script you sent me..... Set RS = db.openrecordset....
    at the end of the script it doesn't like Set DAO = Nothing either. I changed it to Set db= Nothing giving me the same error.

  10. #40
    Brian62 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2009
    Posts
    147
    I wish I could give you a copy of the db but it's connected to SQL. The new error code is-time error 3464. Data type mismatch in criteria expression.

  11. #41
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    If ID_D is a number type then eliminate the apostrophe delimiters which are for text type. Date type criteria would use # delimiter.
    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.

  12. #42
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Try this:

    strsql = "SELECT * FROM dbo_TblRDStudyAuditDocument WHERE ID_D = " & Me.ID_D
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #43
    Brian62 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2009
    Posts
    147
    Still doesn't like it. Still has error 91.

    Private Sub CmdAdd_Click()
    Dim strsql As String
    Dim DAO As DAO.Database
    Dim RS As DAO.Recordset
    Dim LngCnt As Long

    LngCnt = 0

    strsql = "SELECT * FROM dbo_TblRDStudyAuditDocument WHERE ID_D = " & Me.ID_D
    Set DAO = OpenDatabase("W:\RCO\Databases\SQL_RCO_Database.ac cdb")
    Set RS = DAO.OpenRecordset(strsql, dbOpenDynaset, dbSeeChanges)

    LngCnt = 0

    With RS
    If LngCnt > 0 Then
    .MoveFirst
    .Index = "PK_TblRDStudyAuditDocument"
    .MoveLast
    ID_D = .Fields(0) + 1
    .AddNew
    .Fields(0) = ID_D
    .Fields(1) = Studyid
    .Fields(2) = AuditDate
    .Fields(3) = TxtSectionName
    .Fields(4) = DocName
    .Fields(5) = Comments
    .Update
    Else
    .AddNew
    .Fields(0) = 1
    .Fields(1) = Studyid
    .Fields(2) = AuditDate
    .Fields(3) = TxtSectionName
    .Fields(4) = DocName
    .Fields(5) = Comments
    .Update
    ID_D = 1

    End If
    .Close

    End With

    Set DAO = Nothing

    End Sub

  14. #44
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    And we're back to using DAO as a variable?

    Can you import the SQL Server table into the Access db, get rid of any personal info, and post that?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  15. #45
    Brian62 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2009
    Posts
    147
    If I post the db then it will work since the VB worked then. The conversion to SQL as the BE is what is giving me trouble with VB.

Page 3 of 4 FirstFirst 1234 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. "not an index in this table" error
    By everette in forum Access
    Replies: 4
    Last Post: 04-06-2012, 05:03 AM
  2. Replies: 2
    Last Post: 11-04-2011, 02:45 AM
  3. Replies: 1
    Last Post: 04-25-2011, 12:36 PM
  4. "Group By" causes "ODBC--Call Failed" error
    By kaledev in forum Queries
    Replies: 1
    Last Post: 03-09-2011, 02:43 PM
  5. Replies: 4
    Last Post: 06-10-2010, 07:51 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