Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    Understanding recordsets strsql

    I have



    Code:
    Dim db As dao.Database
    Dim rs As dao.Recordset
    Dim strsql As String
    
    
    strsql = "SELECT tblTeacher.JoiningSchool, tblSchools.NewSchoolsID, tblSchools.SchoolName, tblSchools.[1ContactName], tblSchools.[1ContactSurname], tblSchools.SchoolAddress, tblSchools.SchoolPostalAddress, tblSchools.SchoolPostalSuburb, tblSchools.SchoolSuburb, tblSchools.SchoolPostCode, tblSchools.SchoolPhone, tblStates.SchoolState, tblSchools.MemoPerformerNotes, tblSchools.SchoolFax, tblSchools.SchoolEmail " & vbCrLf & _
    "FROM (tblStates RIGHT JOIN (tblSchools RIGHT JOIN (tblJoiningSchoolStatus RIGHT JOIN tblTeacher ON tblJoiningSchoolStatus.JoiningSchoolStatusID = tblTeacher.JoiningSchoolStatusID) ON tblSchools.NewSchoolsID = tblTeacher.NewSchoolsID) ON tblStates.StateID = tblSchools.StateID) RIGHT JOIN (tblStatus RIGHT JOIN ((tblShows RIGHT JOIN (tblBookings RIGHT JOIN tblJncTeacher ON tblBookings.BookingsID = tblJncTeacher.BookingsID) ON tblShows.ShowsID = tblBookings.ShowsID) LEFT JOIN (tblPerformers RIGHT JOIN tblJncShows ON tblPerformers.PerformersID = tblJncShows.PerformersID) ON tblShows.ShowsID = tblJncShows.ShowsID) ON tblStatus.StatusID = tblBookings.StatusID) ON tblTeacher.TeacherID = tblJncTeacher.TeacherID " & vbCrLf & _
    "WHERE (((tblBookings.StatusID)<>5) AND (([tblBookings]![BookingDate]) Between [forms]![frmEndOfYearLetter]![txtFromDate] And [forms]![frmEndOfYearLetter]![txtUntilDate])) " & vbCrLf & _
    "GROUP BY tblTeacher.JoiningSchool, tblSchools.NewSchoolsID, tblSchools.SchoolName, tblSchools.[1ContactName], tblSchools.[1ContactSurname], tblSchools.SchoolAddress, tblSchools.SchoolPostalAddress, tblSchools.SchoolPostalSuburb, tblSchools.SchoolSuburb, tblSchools.SchoolPostCode, tblSchools.SchoolPhone, tblStates.SchoolState, tblSchools.MemoPerformerNotes, tblSchools.SchoolFax, tblSchools.SchoolEmail " & vbCrLf & _
    "ORDER BY tblTeacher.JoiningSchool DESC;"
    
    
    
    
    Set db = CurrentDb()
    Set rs = db.OpenRecordset(strsql)
    
    
    rs.MoveFirst
    Do Until rs.EOF
    rs.Edit
    
    
    
    
    
    
    rs.Update
    rs.MoveNext
    Loop
    MsgBox "All schools have been emailed"
    rs.Close
    Set rs = Nothing
    but I get an error.

    I know that between rs.edit and update that there is no actions (I will add that later)

    I don't know why I am getting an error so I was hoping someone can explain why and help me understand.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Remove the vbCrLf's. Maybe they aren't the issue but they certainly are not necessary.

    What is the error message?

    Did you build the query with Access query builder first?

    Need to concatenate variables. Reference to control on form is variable. Date parameters need # delimiter.

    "WHERE tblBookings.StatusID<>5 AND [tblBookings]![BookingDate] Between #" & [forms]![frmEndOfYearLetter]![txtFromDate] & "# And #" & [forms]![frmEndOfYearLetter]![txtUntilDate] & _
    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
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    Remove the vbCrLf's. Maybe they aren't the issue but they certainly are not necessary.

    What is the error message?

    Did you build the query with Access query builder first?



    Need to concatenate variables. Reference to control on form is variable. Date parameters need # delimiter.

    "WHERE tblBookings.StatusID<>5 AND [tblBookings]![BookingDate] Between #" & [forms]![frmEndOfYearLetter]![txtFromDate] & "# And #" & [forms]![frmEndOfYearLetter]![txtUntilDate] & _
    this is my error

    Click image for larger version. 

Name:	Capture.JPG 
Views:	25 
Size:	18.5 KB 
ID:	14456

    Yes I built from query first - it's working fine for the form to open a report.

    I will update the date delimiter too

  4. #4
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Click image for larger version. 

Name:	Capture.JPG 
Views:	25 
Size:	18.7 KB 
ID:	14457

    It points to this

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Oops! I missed the closing # for the end date:

    "WHERE tblBookings.StatusID<>5 AND [tblBookings]![BookingDate] Between #" & [forms]![frmEndOfYearLetter]![txtFromDate] & "# And #" & [forms]![frmEndOfYearLetter]![txtUntilDate] & "#" & _
    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.

  6. #6
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    Oops! I missed the closing # for the end date:

    "WHERE tblBookings.StatusID<>5 AND [tblBookings]![BookingDate] Between #" & [forms]![frmEndOfYearLetter]![txtFromDate] & "# And #" & [forms]![frmEndOfYearLetter]![txtUntilDate] & "#" & _
    Is that all it is? my poor concatenation?

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    That and the unnecessary vbCrLfs is all I can see.

    Did you add the vbCrLf codes?
    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.

  8. #8
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    That and the unnecessary vbCrLfs is all I can see.

    Did you add the vbCrLf codes?
    no, to save time I made a form that converts sql - it adds the vbCrLf

    I just paste it in and press convert.

    Click image for larger version. 

Name:	Capture.JPG 
Views:	22 
Size:	36.7 KB 
ID:	14458

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Okay, as I said, the vbCrLf probably not issue.

    Just watch out for dynamic parameters when pasting from Access query to VBA.
    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.

  10. #10
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    Okay, as I said, the vbCrLf probably not issue.

    Just watch out for dynamic parameters when pasting from Access query to VBA.
    just realized it's a locked form (groupby) so no edit or update

    Can you edit a table field if it has the same id?

    say

    if isnull(rs!SchoolEmail) then

    find table with same id and edit field?

  11. #11
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Also the trick I used to get

    sendobject. acreport "frmReport" to send as pdf format to each individual ID was manipulating the criteria in the report's record source to refer to the current record ID [forms]![frmBookingsTermAheadEmails]![TeacherID]

    however since I am using rs!

    can you refer to a record source in the criteria of a query?

    i.e. recordsource!rs!TeacherID

  12. #12
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Also I am thinking if I make

    dim storedID as string

    then have the report record source change to strsql2 so

    reports!rptYearLetter.recordsource = strsql2

    storedID = rs!teacherid

    and put say

    strsql2 = the new recordsource but with storedID as criteria in the where

    would that work?!

    crosses fingers and hopes june says yes...

  13. #13
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Cannot refer to a recordset in a saved Access query object.

    Cannot change the RecordSource of report if it is in Preview but can if it is in Report view.
    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.

  14. #14
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Why do you have so many fields in your SQL? What happens if you build a select query that only has the fields you will be updating and a PK?

    You could use a form's recordset clone and loop through it while nesting your update thing.

  15. #15
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by ItsMe View Post
    Why do you have so many fields in your SQL? What happens if you build a select query that only has the fields you will be updating and a PK?
    The form filters those fields, lots of conditions - but I will look to making it smaller

    Quote Originally Posted by ItsMe View Post
    You could use a form's recordset clone and loop through it while nesting your update thing.
    I don't quite understand...

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Need help understanding capabilities
    By squall in forum Database Design
    Replies: 2
    Last Post: 08-27-2012, 04:28 PM
  2. VBA strSQL mismatch
    By SPW_12 in forum Programming
    Replies: 12
    Last Post: 07-31-2012, 07:47 PM
  3. Need to add 2nd criteria to strSQL
    By robsworld78 in forum Forms
    Replies: 8
    Last Post: 08-23-2011, 02:57 PM
  4. DLookup in strSQL for OpenRecordset
    By szucker1 in forum Programming
    Replies: 2
    Last Post: 07-30-2011, 06:00 PM
  5. Recordsets, add new, DAO and ADO
    By Arca in forum Programming
    Replies: 1
    Last Post: 04-07-2008, 03:57 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