473,396 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Recordset rs.Find return results

78
In my database I have a varying amount of thins set up. I am trying to display multiple shifts for each day of the month in a calendar form.

I have the calendar set up properly to display the days. I have the correct information generated in table.

I am having trouble displaying multiple records. Right now it only displays one record. Either the first, last or next or whatever I call.

I will include the code below for the section where it occurs. Any help would be appreciated. I am stumped on this one.

Expand|Select|Wrap|Line Numbers
  1. Public Sub PutInData()
  2. Dim SQL As String
  3. Dim f As Form
  4. Dim db As DAO.Database
  5. Dim rs As DAO.Recordset
  6. Dim MyDate As Date
  7. Dim i As Integer
  8.  
  9. Set f = Forms!frmCalendar
  10.  
  11.     For i = 1 To 37
  12.         f("text" & i) = Null
  13.     Next i
  14.  
  15.     SQL = "SELECT * FROM [qryShifts] WHERE ((MONTH(ShiftDetailDate) = " & f!month & " AND YEAR(ShiftDetailDate) = " & f!year & ")) ORDER BY tblShiftDetail.ShiftDetailDate, tblShiftDetail.ShiftNumber, tblEmployee.EmployeeNumber;"
  16.  
  17.     Set db = CurrentDb()
  18.     Set rs = db.OpenRecordset(SQL)
  19.  
  20.     If rs.RecordCount > 0 Then
  21.         For i = 1 To 37
  22.             If IsDate(f("date" & i)) Then
  23.                 MyDate = Format((f("date" & i)), "mm/dd/yyyy")
  24.                 rs.FindFirst ("ShiftDetailDate = #" & MyDate & "#")
  25.                     If Not rs.NoMatch Then
  26.                         f("text" & i) = rs!EmployeeFirstName & " " & rs!EmployeeLastName & " " & rs!ShiftStartTime & "-" & rs!ShiftEndTime
  27.                     End If
  28.             End If
  29.         Next i
  30.     End If
  31.  
  32.     rs.Close
  33.     Set rs = Nothing
  34.     Set db = Nothing
  35.  
  36. End Sub
  37.  
Thank you
Nick
Apr 22 '08 #1
14 3895
ADezii
8,834 Expert 8TB
In my database I have a varying amount of thins set up. I am trying to display multiple shifts for each day of the month in a calendar form.

I have the calendar set up properly to display the days. I have the correct information generated in table.

I am having trouble displaying multiple records. Right now it only displays one record. Either the first, last or next or whatever I call.

I will include the code below for the section where it occurs. Any help would be appreciated. I am stumped on this one.

Expand|Select|Wrap|Line Numbers
  1. Public Sub PutInData()
  2. Dim SQL As String
  3. Dim f As Form
  4. Dim db As DAO.Database
  5. Dim rs As DAO.Recordset
  6. Dim MyDate As Date
  7. Dim i As Integer
  8.  
  9. Set f = Forms!frmCalendar
  10.  
  11.     For i = 1 To 37
  12.         f("text" & i) = Null
  13.     Next i
  14.  
  15.     SQL = "SELECT * FROM [qryShifts] WHERE ((MONTH(ShiftDetailDate) = " & f!month & " AND YEAR(ShiftDetailDate) = " & f!year & ")) ORDER BY tblShiftDetail.ShiftDetailDate, tblShiftDetail.ShiftNumber, tblEmployee.EmployeeNumber;"
  16.  
  17.     Set db = CurrentDb()
  18.     Set rs = db.OpenRecordset(SQL)
  19.  
  20.     If rs.RecordCount > 0 Then
  21.         For i = 1 To 37
  22.             If IsDate(f("date" & i)) Then
  23.                 MyDate = Format((f("date" & i)), "mm/dd/yyyy")
  24.                 rs.FindFirst ("ShiftDetailDate = #" & MyDate & "#")
  25.                     If Not rs.NoMatch Then
  26.                         f("text" & i) = rs!EmployeeFirstName & " " & rs!EmployeeLastName & " " & rs!ShiftStartTime & "-" & rs!ShiftEndTime
  27.                     End If
  28.             End If
  29.         Next i
  30.     End If
  31.  
  32.     rs.Close
  33.     Set rs = Nothing
  34.     Set db = Nothing
  35.  
  36. End Sub
  37.  
Thank you
Nick
You can try this logic out, but I can't guarantee anything since it is past my bedtime, and my eyes are getting droopy (LOL). Let me know how you make out:
Expand|Select|Wrap|Line Numbers
  1. Public Sub PutInData()
  2. Dim SQL As String
  3. Dim f As Form
  4. Dim db As DAO.Database
  5. Dim rs As DAO.Recordset
  6. Dim MyDate As Date
  7. Dim i As Integer
  8.  
  9. Set f = Forms!frmCalendar
  10.  
  11. For i = 1 To 37
  12.   f("text" & i) = Null
  13. Next i
  14.  
  15. SQL = "SELECT * FROM [qryShifts] WHERE ((MONTH(ShiftDetailDate) = " & f!Month & _
  16.       " AND YEAR(ShiftDetailDate) = " & f!Year & ")) ORDER BY tblShiftDetail.ShiftDetailDate, " & _
  17.       "tblShiftDetail.ShiftNumber, tblEmployee.EmployeeNumber;"
  18.  
  19. Set db = CurrentDb()
  20. Set rs = db.OpenRecordset(SQL)
  21.  
  22. If rs.RecordCount > 0 Then
  23.   For i = 1 To 37
  24.     If IsDate(f("date" & i)) Then
  25.       MyDate = Format((f("date" & i)), "mm/dd/yyyy")
  26.       Do While Not rs.EOF
  27.         If rs![ShiftDetailDate] = "#" & MyDate & "#" Then
  28.           f("text" & i) = rs!EmployeeFirstName & " " & rs!EmployeeLastName & " " & _
  29.                           rs!ShiftStartTime & "-" & rs!ShiftEndTime
  30.             Exit Do
  31.         End If
  32.         rs.MoveNext
  33.       Loop
  34.       rs.MoveFirst
  35.     End If
  36.   Next i
  37. End If
  38.  
  39. rs.Close
  40. Set rs = Nothing
  41. Set db = Nothing
  42. End Sub
Apr 23 '08 #2
nspader
78
No Adezzi That didnt work. I am not sure what exactly is going on but clearly it is not recalling multiple files. The logic there seems accurate but do I need to save it in a different place to recall it? I am not sure.

Thanks for the try though...late nights can cause delirium...one should only take in small quantities.

Nick
Apr 23 '08 #3
ADezii
8,834 Expert 8TB
No Adezzi That didnt work. I am not sure what exactly is going on but clearly it is not recalling multiple files. The logic there seems accurate but do I need to save it in a different place to recall it? I am not sure.

Thanks for the try though...late nights can cause delirium...one should only take in small quantities.

Nick
Hello Nick, this time let's try Plan B since I'm actually awake now, not that this will make a difference. (LOL).
Expand|Select|Wrap|Line Numbers
  1. Public Sub PutInData()
  2. Dim SQL As String
  3. Dim f As Form
  4. Dim db As DAO.Database
  5. Dim rs As DAO.Recordset
  6. Dim MyDate As Date
  7. Dim i As Integer
  8. Dim strShiftDetails As String
  9.  
  10. Set f = Forms!frmCalendar
  11.  
  12. For i = 1 To 37
  13.   f("text" & i) = Null
  14. Next i
  15.  
  16. SQL = "SELECT * FROM [qryShifts] WHERE ((MONTH(ShiftDetailDate) = " & f!Month & _
  17.       " AND YEAR(ShiftDetailDate) = " & f!Year & ")) ORDER BY tblShiftDetail.ShiftDetailDate, " & _
  18.       "tblShiftDetail.ShiftNumber, tblEmployee.EmployeeNumber;"
  19.  
  20. Set db = CurrentDb()
  21. Set rs = db.OpenRecordset(SQL)
  22.  
  23. If rs.RecordCount > 0 Then
  24.   For i = 1 To 37
  25.     If IsDate(f("date" & i)) Then
  26.       MyDate = Format((f("date" & i)), "mm/dd/yyyy")
  27.       Do While Not rs.EOF
  28.         If rs![ShiftDetailDate] = "#" & MyDate & "#" Then
  29.           strShiftDetails = strShiftDetails & rs!EmployeeFirstName & " " & rs!EmployeeLastName & " " & _
  30.                             rs!ShiftStartTime & "-" & rs!ShiftEndTime & vbCrLf
  31.         End If
  32.         rs.MoveNext
  33.       Loop
  34.       f("text" & i) = Left$(strShiftDetails, Len(strShiftDetails) - 2)  'Strip vbCrLf
  35.       strShiftDetails = ""      'Reset
  36.       rs.MoveFirst
  37.     End If
  38.   Next i
  39. End If
  40.  
  41. rs.Close
  42. Set rs = Nothing
  43. Set db = Nothing
  44. End Sub
Apr 23 '08 #4
nspader
78
I am sorry to say that didnt work either. I really appreciate your attempts though. I do not fully understand why neither procedure worked. Under my thoughts either should have worked as well. Any other help would be appreciated.

Nick
Apr 23 '08 #5
nspader
78
aDezii

You had the right idea. I have something going on now, where I can see the second file as well. However I do not have the loop working. I am going to work on it a little longer and will post if I need help or when I get it. Thank you for your help so far though.

Nick
Apr 23 '08 #6
nspader
78
Ok, Now the Code below returns 2 files. I have commented out the Loop because when Used it only returns the first record. Presently there are 4 records to return, but depending on Employee Number that will change So I do not want to depend on that.

Can anyone help me figure out this Loop issue?

ADezii, maybe you can take it from here. You helped me get here between the two of us maybe we can figure it out. LOL

Many Thanks
Nick

Expand|Select|Wrap|Line Numbers
  1. Public Sub PutInData()
  2. Dim sql As String
  3. Dim f As Form
  4. Dim db As DAO.Database
  5. Dim rs As DAO.Recordset
  6. Dim MyDate As Date
  7. Dim i As Integer
  8. Dim strShiftDetails As String
  9.  
  10. Set f = Forms!frmCalendar
  11.  
  12.     For i = 1 To 37
  13.         f("text" & i) = Null
  14.     Next i
  15.  
  16.     sql = "SELECT * FROM [qryShifts] WHERE ((MONTH(ShiftDetailDate) = " & f!month & " AND YEAR(ShiftDetailDate) = " & f!year & ")) ORDER BY tblShiftDetail.ShiftDetailDate, tblEmployee.EmployeeFirstName;"
  17.  
  18.     Set db = CurrentDb()
  19.     Set rs = db.OpenRecordset(sql)
  20.  
  21.     If rs.RecordCount > 0 Then
  22.         For i = 1 To 37
  23.             If IsDate(f("date" & i)) Then
  24.                 MyDate = Format((f("date" & i)), "mm/dd/yyyy")
  25.                 rs.FindFirst ("ShiftDetailDate = #" & MyDate & "#")
  26.                     If Not rs.NoMatch Then
  27.                         strShiftDetails = rs!EmployeeFirstName & " " & rs!EmployeeLastName & " " & rs!ShiftStartTime & "-" & rs!ShiftEndTime
  28.                         rs.FindNext ("ShiftDetailDate = #" & MyDate & "#")
  29.                            ' Do While rs!ShiftDetailDate = "#' & MyDate $ '#"
  30.                                 strShiftDetails = strShiftDetails & vbCrLf & rs!EmployeeFirstName & " " & rs!EmployeeLastName & " " & rs!ShiftStartTime & "-" & rs!ShiftEndTime
  31.                             'rs.MoveNext
  32.                             'Loop
  33.                         f("text" & i) = strShiftDetails
  34.                   End If
  35.             strShiftDetails = ""
  36.             End If
  37.         Next i
  38.     End If
  39.  
  40.     rs.Close
  41.     Set rs = Nothing
  42.     Set db = Nothing
  43.  
  44. End Sub
  45.  
Apr 23 '08 #7
ADezii
8,834 Expert 8TB
Ok, Now the Code below returns 2 files. I have commented out the Loop because when Used it only returns the first record. Presently there are 4 records to return, but depending on Employee Number that will change So I do not want to depend on that.

Can anyone help me figure out this Loop issue?

ADezii, maybe you can take it from here. You helped me get here between the two of us maybe we can figure it out. LOL

Many Thanks
Nick

Expand|Select|Wrap|Line Numbers
  1. Public Sub PutInData()
  2. Dim sql As String
  3. Dim f As Form
  4. Dim db As DAO.Database
  5. Dim rs As DAO.Recordset
  6. Dim MyDate As Date
  7. Dim i As Integer
  8. Dim strShiftDetails As String
  9.  
  10. Set f = Forms!frmCalendar
  11.  
  12.     For i = 1 To 37
  13.         f("text" & i) = Null
  14.     Next i
  15.  
  16.     sql = "SELECT * FROM [qryShifts] WHERE ((MONTH(ShiftDetailDate) = " & f!month & " AND YEAR(ShiftDetailDate) = " & f!year & ")) ORDER BY tblShiftDetail.ShiftDetailDate, tblEmployee.EmployeeFirstName;"
  17.  
  18.     Set db = CurrentDb()
  19.     Set rs = db.OpenRecordset(sql)
  20.  
  21.     If rs.RecordCount > 0 Then
  22.         For i = 1 To 37
  23.             If IsDate(f("date" & i)) Then
  24.                 MyDate = Format((f("date" & i)), "mm/dd/yyyy")
  25.                 rs.FindFirst ("ShiftDetailDate = #" & MyDate & "#")
  26.                     If Not rs.NoMatch Then
  27.                         strShiftDetails = rs!EmployeeFirstName & " " & rs!EmployeeLastName & " " & rs!ShiftStartTime & "-" & rs!ShiftEndTime
  28.                         rs.FindNext ("ShiftDetailDate = #" & MyDate & "#")
  29.                            ' Do While rs!ShiftDetailDate = "#' & MyDate $ '#"
  30.                                 strShiftDetails = strShiftDetails & vbCrLf & rs!EmployeeFirstName & " " & rs!EmployeeLastName & " " & rs!ShiftStartTime & "-" & rs!ShiftEndTime
  31.                             'rs.MoveNext
  32.                             'Loop
  33.                         f("text" & i) = strShiftDetails
  34.                   End If
  35.             strShiftDetails = ""
  36.             End If
  37.         Next i
  38.     End If
  39.  
  40.     rs.Close
  41.     Set rs = Nothing
  42.     Set db = Nothing
  43.  
  44. End Sub
  45.  
The problem would be much easier to diagnose if you E-Mailed me a copy of the Database or a subset of it, is that possible? If so, I can assure you complete privacy.
Apr 23 '08 #8
nspader
78
Absolutely if you want to PM me you email I will send it off.

Thank you

NIck
Apr 24 '08 #9
ADezii
8,834 Expert 8TB
Absolutely if you want to PM me you email I will send it off.

Thank you

NIck
Check your Private Messages, you'll have my Address there soon. Please provide all relevant Details as well.
Apr 24 '08 #10
nspader
78
Check your Private Messages, you'll have my Address there soon. Please provide all relevant Details as well.

Azii,

I did figure it out. It is probably a little sloppy but it works. I am working on some other stuf but will post on monday what I have so you can see it.

Thanks

Nick
Apr 25 '08 #11
ADezii
8,834 Expert 8TB
Azii,

I did figure it out. It is probably a little sloppy but it works. I am working on some other stuf but will post on monday what I have so you can see it.

Thanks

Nick
I actually have the revised code which I'll post tonight.
Apr 25 '08 #12
ADezii
8,834 Expert 8TB
Azii,

I did figure it out. It is probably a little sloppy but it works. I am working on some other stuf but will post on monday what I have so you can see it.

Thanks

Nick
  1. Below please find the revised code for the PutInData() Sub-Routine. It has been tested, and is fully operational. You can just replace replace your entire Procedure with this new code, or Copy and Paste over the existing code.
    Expand|Select|Wrap|Line Numbers
    1. Public Sub PutInData()
    2. On Error GoTo Err_PutIndata
    3. Dim sql As String
    4. Dim f As Form
    5. Dim db As DAO.Database
    6. Dim rs As DAO.Recordset
    7. Dim MyDate As Date
    8. Dim i As Integer
    9. Dim strShiftDetails As String
    10.  
    11. Set f = Forms!frmCalendar
    12.  
    13. For i = 1 To 37
    14.   f("text" & i) = Null
    15. Next i
    16.  
    17. sql = "SELECT * FROM [qryShifts] WHERE ((MONTH(ShiftDetailDate) = " & _
    18.        f!month & " AND YEAR(ShiftDetailDate) = " & f!year & ")) " & _
    19.        "ORDER BY tblShiftDetail.ShiftDetailDate, tblEmployee.EmployeeFirstName;"
    20.  
    21. Set db = CurrentDb()
    22. Set rs = db.OpenRecordset(sql)
    23.  
    24. 'Test Loop for Debugging purposes
    25. 'Do While Not rs.EOF
    26.   'Debug.Print rs![ShiftDetailDate] & " ==> " & rs!EmployeeFirstName & " " & _
    27.               'rs!EmployeeLastName & " " & rs!ShiftStartTime & "-" & rs!ShiftEndTime
    28.   'rs.MoveNext
    29. 'Loop
    30.   'Exit Sub
    31.  
    32. If rs.RecordCount > 0 Then
    33.   For i = 1 To 37
    34.     If IsDate(f("date" & i)) Then
    35.     MyDate = Format((f("date" & i)), "mm/dd/yyyy")
    36.       Do While Not rs.EOF
    37.         If rs![ShiftDetailDate] = MyDate Then
    38.           strShiftDetails = strShiftDetails & rs!EmployeeFirstName & " " & rs!EmployeeLastName & " " & _
    39.                             rs!ShiftStartTime & "-" & rs!ShiftEndTime & vbCrLf
    40.         End If
    41.         rs.MoveNext
    42.       Loop
    43.       If Len(strShiftDetails) > 0 Then
    44.         f("text" & i) = Left$(strShiftDetails, Len(strShiftDetails) - 2)      'Strip vbCrLf
    45.       End If
    46.       strShiftDetails = ""      'Reset
    47.       rs.MoveFirst
    48.     End If
    49.   Next i
    50. End If
    51.  
    52. rs.Close
    53. Set rs = Nothing
    54. Set db = Nothing
    55.  
    56. Exit_PutIndata:
    57.   Exit Sub
    58.  
    59. Err_PutIndata:
    60.   MsgBox Err.Description, vbExclamation, "Error in PutIndata()"
    61.   Resume Exit_PutIndata
    62. End Sub
  2. Be advised that the PutInData() Routine was being called twice when frmCalendar Opens. In the frmCalendar_Load() Event, the next to the last line calls the Cal([month], [year]) Routine. The last line in this Sub-Procedure calls the PutInData() Routine, then returns code execution back to the frmCalendar_Load() Event. The last line in the Load() Event also calls the Cal(m, y) Routine. Since the call to PutInData() needs to exist independently from the Call in the Load() Event, delete the last line in the frmCalendar_Load() Event, namely, Call Cal([month], [year]). Just download the Attachment to see what I mean.
  3. The way frmCalendar is structured, you can not display > 4 Shifts per Day, which is evidenced by only 4 of the 5 Shifts being displayed for April 14, 2008. You need to make provisions for this also.
  4. Any other questions, feel free to ask.
Apr 25 '08 #13
nspader
78
That works Perfectlly. Much better then the sloppy version I came up with. The dispplay problem on the calendar is simply text size. Visually you could not see it but it was there.

I have added some more functions to the db and made it more visually pleasing...fixing the problem with not showing more then 4 employees on the calendar. Thank you so much for your help.

Now, I am at the point that I am going to add in time off dates and specific shift dates. I honestly am not sure where to start but I am trying some different things. Any help on this would be appreaciated.

Thank you for everything

Nick
Apr 29 '08 #14
ADezii
8,834 Expert 8TB
That works Perfectlly. Much better then the sloppy version I came up with. The dispplay problem on the calendar is simply text size. Visually you could not see it but it was there.

I have added some more functions to the db and made it more visually pleasing...fixing the problem with not showing more then 4 employees on the calendar. Thank you so much for your help.

Now, I am at the point that I am going to add in time off dates and specific shift dates. I honestly am not sure where to start but I am trying some different things. Any help on this would be appreaciated.

Thank you for everything

Nick
You are quite welcome, Nick.
Apr 29 '08 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: dmiller23462 | last post by:
My brain is nuked....Can anybody tell me right off the bat what is wrong with this code? Along with any glaring errors, please let me know the syntax to display a message (Response.Write would be...
1
by: Robin Hammond | last post by:
Can anybody tell me why a) when running a stored proc from an asp page to return a recordset the command succeeds if the sp queries an existing table directly, but b) if the stored proc populates...
19
by: Adam Short | last post by:
I am trying to write a routine that will connect a .NET server with a classic ASP server. I know the following code doesn't work! The data is being returned as a dataset, however ASP does not...
3
by: Mika | last post by:
Is it possible to perform functions on a recordset (rather than on the source database), e.g. COUNT, MAX etc The reason I would like to do this is because I have a hugely complex view which...
9
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
7
by: Jean | last post by:
Hello, I have a form that performs a search, according to criteria that a user enters into the text boxes. When the user clicks on „Search", a SQL string (say strSQL) is built up with the...
6
by: lenny | last post by:
Hi, I've been trying to use a Sub or Function in VBA to connect to a database, make a query and return the recordset that results from the query. The connection to the database and the query...
5
by: Henrik | last post by:
The problem is (using MS Access 2003) I am unable to retrieve long strings (255 chars) from calculated fields through a recordset. The data takes the trip in three phases: 1. A custom public...
6
by: Oko | last post by:
I'm currently developing an MS Access Data Project (.adp) in MS Access 2002. One of the reports within the DB uses data that is Dynamic and cannot be stored on the SQL Server. To resolve this, I...
2
by: wallconor | last post by:
Hi, I am having a problem using Dreamweaver CS3 standard recordset paging behavior. It doesn’t seem to work when I pass parameter values from a FORM on my search page, to the recordset on my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.