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. -
Public Sub PutInData()
-
Dim SQL As String
-
Dim f As Form
-
Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
Dim MyDate As Date
-
Dim i As Integer
-
-
Set f = Forms!frmCalendar
-
-
For i = 1 To 37
-
f("text" & i) = Null
-
Next i
-
-
SQL = "SELECT * FROM [qryShifts] WHERE ((MONTH(ShiftDetailDate) = " & f!month & " AND YEAR(ShiftDetailDate) = " & f!year & ")) ORDER BY tblShiftDetail.ShiftDetailDate, tblShiftDetail.ShiftNumber, tblEmployee.EmployeeNumber;"
-
-
Set db = CurrentDb()
-
Set rs = db.OpenRecordset(SQL)
-
-
If rs.RecordCount > 0 Then
-
For i = 1 To 37
-
If IsDate(f("date" & i)) Then
-
MyDate = Format((f("date" & i)), "mm/dd/yyyy")
-
rs.FindFirst ("ShiftDetailDate = #" & MyDate & "#")
-
If Not rs.NoMatch Then
-
f("text" & i) = rs!EmployeeFirstName & " " & rs!EmployeeLastName & " " & rs!ShiftStartTime & "-" & rs!ShiftEndTime
-
End If
-
End If
-
Next i
-
End If
-
-
rs.Close
-
Set rs = Nothing
-
Set db = Nothing
-
-
End Sub
-
Thank you
Nick
14 3895
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. -
Public Sub PutInData()
-
Dim SQL As String
-
Dim f As Form
-
Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
Dim MyDate As Date
-
Dim i As Integer
-
-
Set f = Forms!frmCalendar
-
-
For i = 1 To 37
-
f("text" & i) = Null
-
Next i
-
-
SQL = "SELECT * FROM [qryShifts] WHERE ((MONTH(ShiftDetailDate) = " & f!month & " AND YEAR(ShiftDetailDate) = " & f!year & ")) ORDER BY tblShiftDetail.ShiftDetailDate, tblShiftDetail.ShiftNumber, tblEmployee.EmployeeNumber;"
-
-
Set db = CurrentDb()
-
Set rs = db.OpenRecordset(SQL)
-
-
If rs.RecordCount > 0 Then
-
For i = 1 To 37
-
If IsDate(f("date" & i)) Then
-
MyDate = Format((f("date" & i)), "mm/dd/yyyy")
-
rs.FindFirst ("ShiftDetailDate = #" & MyDate & "#")
-
If Not rs.NoMatch Then
-
f("text" & i) = rs!EmployeeFirstName & " " & rs!EmployeeLastName & " " & rs!ShiftStartTime & "-" & rs!ShiftEndTime
-
End If
-
End If
-
Next i
-
End If
-
-
rs.Close
-
Set rs = Nothing
-
Set db = Nothing
-
-
End Sub
-
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: - Public Sub PutInData()
-
Dim SQL As String
-
Dim f As Form
-
Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
Dim MyDate As Date
-
Dim i As Integer
-
-
Set f = Forms!frmCalendar
-
-
For i = 1 To 37
-
f("text" & i) = Null
-
Next i
-
-
SQL = "SELECT * FROM [qryShifts] WHERE ((MONTH(ShiftDetailDate) = " & f!Month & _
-
" AND YEAR(ShiftDetailDate) = " & f!Year & ")) ORDER BY tblShiftDetail.ShiftDetailDate, " & _
-
"tblShiftDetail.ShiftNumber, tblEmployee.EmployeeNumber;"
-
-
Set db = CurrentDb()
-
Set rs = db.OpenRecordset(SQL)
-
-
If rs.RecordCount > 0 Then
-
For i = 1 To 37
-
If IsDate(f("date" & i)) Then
-
MyDate = Format((f("date" & i)), "mm/dd/yyyy")
-
Do While Not rs.EOF
-
If rs![ShiftDetailDate] = "#" & MyDate & "#" Then
-
f("text" & i) = rs!EmployeeFirstName & " " & rs!EmployeeLastName & " " & _
-
rs!ShiftStartTime & "-" & rs!ShiftEndTime
-
Exit Do
-
End If
-
rs.MoveNext
-
Loop
-
rs.MoveFirst
-
End If
-
Next i
-
End If
-
-
rs.Close
-
Set rs = Nothing
-
Set db = Nothing
-
End Sub
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
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). -
Public Sub PutInData()
-
Dim SQL As String
-
Dim f As Form
-
Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
Dim MyDate As Date
-
Dim i As Integer
-
Dim strShiftDetails As String
-
-
Set f = Forms!frmCalendar
-
-
For i = 1 To 37
-
f("text" & i) = Null
-
Next i
-
-
SQL = "SELECT * FROM [qryShifts] WHERE ((MONTH(ShiftDetailDate) = " & f!Month & _
-
" AND YEAR(ShiftDetailDate) = " & f!Year & ")) ORDER BY tblShiftDetail.ShiftDetailDate, " & _
-
"tblShiftDetail.ShiftNumber, tblEmployee.EmployeeNumber;"
-
-
Set db = CurrentDb()
-
Set rs = db.OpenRecordset(SQL)
-
-
If rs.RecordCount > 0 Then
-
For i = 1 To 37
-
If IsDate(f("date" & i)) Then
-
MyDate = Format((f("date" & i)), "mm/dd/yyyy")
-
Do While Not rs.EOF
-
If rs![ShiftDetailDate] = "#" & MyDate & "#" Then
-
strShiftDetails = strShiftDetails & rs!EmployeeFirstName & " " & rs!EmployeeLastName & " " & _
-
rs!ShiftStartTime & "-" & rs!ShiftEndTime & vbCrLf
-
End If
-
rs.MoveNext
-
Loop
-
f("text" & i) = Left$(strShiftDetails, Len(strShiftDetails) - 2) 'Strip vbCrLf
-
strShiftDetails = "" 'Reset
-
rs.MoveFirst
-
End If
-
Next i
-
End If
-
-
rs.Close
-
Set rs = Nothing
-
Set db = Nothing
-
End Sub
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
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
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 -
Public Sub PutInData()
-
Dim sql As String
-
Dim f As Form
-
Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
Dim MyDate As Date
-
Dim i As Integer
-
Dim strShiftDetails As String
-
-
Set f = Forms!frmCalendar
-
-
For i = 1 To 37
-
f("text" & i) = Null
-
Next i
-
-
sql = "SELECT * FROM [qryShifts] WHERE ((MONTH(ShiftDetailDate) = " & f!month & " AND YEAR(ShiftDetailDate) = " & f!year & ")) ORDER BY tblShiftDetail.ShiftDetailDate, tblEmployee.EmployeeFirstName;"
-
-
Set db = CurrentDb()
-
Set rs = db.OpenRecordset(sql)
-
-
If rs.RecordCount > 0 Then
-
For i = 1 To 37
-
If IsDate(f("date" & i)) Then
-
MyDate = Format((f("date" & i)), "mm/dd/yyyy")
-
rs.FindFirst ("ShiftDetailDate = #" & MyDate & "#")
-
If Not rs.NoMatch Then
-
strShiftDetails = rs!EmployeeFirstName & " " & rs!EmployeeLastName & " " & rs!ShiftStartTime & "-" & rs!ShiftEndTime
-
rs.FindNext ("ShiftDetailDate = #" & MyDate & "#")
-
' Do While rs!ShiftDetailDate = "#' & MyDate $ '#"
-
strShiftDetails = strShiftDetails & vbCrLf & rs!EmployeeFirstName & " " & rs!EmployeeLastName & " " & rs!ShiftStartTime & "-" & rs!ShiftEndTime
-
'rs.MoveNext
-
'Loop
-
f("text" & i) = strShiftDetails
-
End If
-
strShiftDetails = ""
-
End If
-
Next i
-
End If
-
-
rs.Close
-
Set rs = Nothing
-
Set db = Nothing
-
-
End Sub
-
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 -
Public Sub PutInData()
-
Dim sql As String
-
Dim f As Form
-
Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
Dim MyDate As Date
-
Dim i As Integer
-
Dim strShiftDetails As String
-
-
Set f = Forms!frmCalendar
-
-
For i = 1 To 37
-
f("text" & i) = Null
-
Next i
-
-
sql = "SELECT * FROM [qryShifts] WHERE ((MONTH(ShiftDetailDate) = " & f!month & " AND YEAR(ShiftDetailDate) = " & f!year & ")) ORDER BY tblShiftDetail.ShiftDetailDate, tblEmployee.EmployeeFirstName;"
-
-
Set db = CurrentDb()
-
Set rs = db.OpenRecordset(sql)
-
-
If rs.RecordCount > 0 Then
-
For i = 1 To 37
-
If IsDate(f("date" & i)) Then
-
MyDate = Format((f("date" & i)), "mm/dd/yyyy")
-
rs.FindFirst ("ShiftDetailDate = #" & MyDate & "#")
-
If Not rs.NoMatch Then
-
strShiftDetails = rs!EmployeeFirstName & " " & rs!EmployeeLastName & " " & rs!ShiftStartTime & "-" & rs!ShiftEndTime
-
rs.FindNext ("ShiftDetailDate = #" & MyDate & "#")
-
' Do While rs!ShiftDetailDate = "#' & MyDate $ '#"
-
strShiftDetails = strShiftDetails & vbCrLf & rs!EmployeeFirstName & " " & rs!EmployeeLastName & " " & rs!ShiftStartTime & "-" & rs!ShiftEndTime
-
'rs.MoveNext
-
'Loop
-
f("text" & i) = strShiftDetails
-
End If
-
strShiftDetails = ""
-
End If
-
Next i
-
End If
-
-
rs.Close
-
Set rs = Nothing
-
Set db = Nothing
-
-
End Sub
-
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.
Absolutely if you want to PM me you email I will send it off.
Thank you
NIck
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.
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
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.
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
- 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.
-
Public Sub PutInData()
-
On Error GoTo Err_PutIndata
-
Dim sql As String
-
Dim f As Form
-
Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
Dim MyDate As Date
-
Dim i As Integer
-
Dim strShiftDetails As String
-
-
Set f = Forms!frmCalendar
-
-
For i = 1 To 37
-
f("text" & i) = Null
-
Next i
-
-
sql = "SELECT * FROM [qryShifts] WHERE ((MONTH(ShiftDetailDate) = " & _
-
f!month & " AND YEAR(ShiftDetailDate) = " & f!year & ")) " & _
-
"ORDER BY tblShiftDetail.ShiftDetailDate, tblEmployee.EmployeeFirstName;"
-
-
Set db = CurrentDb()
-
Set rs = db.OpenRecordset(sql)
-
-
'Test Loop for Debugging purposes
-
'Do While Not rs.EOF
-
'Debug.Print rs![ShiftDetailDate] & " ==> " & rs!EmployeeFirstName & " " & _
-
'rs!EmployeeLastName & " " & rs!ShiftStartTime & "-" & rs!ShiftEndTime
-
'rs.MoveNext
-
'Loop
-
'Exit Sub
-
-
If rs.RecordCount > 0 Then
-
For i = 1 To 37
-
If IsDate(f("date" & i)) Then
-
MyDate = Format((f("date" & i)), "mm/dd/yyyy")
-
Do While Not rs.EOF
-
If rs![ShiftDetailDate] = MyDate Then
-
strShiftDetails = strShiftDetails & rs!EmployeeFirstName & " " & rs!EmployeeLastName & " " & _
-
rs!ShiftStartTime & "-" & rs!ShiftEndTime & vbCrLf
-
End If
-
rs.MoveNext
-
Loop
-
If Len(strShiftDetails) > 0 Then
-
f("text" & i) = Left$(strShiftDetails, Len(strShiftDetails) - 2) 'Strip vbCrLf
-
End If
-
strShiftDetails = "" 'Reset
-
rs.MoveFirst
-
End If
-
Next i
-
End If
-
-
rs.Close
-
Set rs = Nothing
-
Set db = Nothing
-
-
Exit_PutIndata:
-
Exit Sub
-
-
Err_PutIndata:
-
MsgBox Err.Description, vbExclamation, "Error in PutIndata()"
-
Resume Exit_PutIndata
-
End Sub
- 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.
- 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.
- Any other questions, feel free to ask.
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |