473,471 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Calendar tool creating random records

105 New Member
Hey everyone!

I have a subform form with a textbox, 2 command buttons, and an ActiveX calendar. The form loads with Calendar.Value = Now(). The textbox is blank. The two buttons are Save, and Cancel.

Here's my problem, when I click a date on the calendar, it assigns the value to the textbox, which has a control source of ReadDate. If I click the close button on the main form and I look at my recordsource table, a record with the date that was last selected from the ActiveX calendar has been created...Why? I didn't tell it to save?

Thanks in advance for your help!!
Joseph
Mar 3 '08 #1
6 1548
JustJim
407 Recognized Expert Contributor
Hey everyone!

I have a subform form with a textbox, 2 command buttons, and an ActiveX calendar. The form loads with Calendar.Value = Now(). The textbox is blank. The two buttons are Save, and Cancel.

Here's my problem, when I click a date on the calendar, it assigns the value to the textbox, which has a control source of ReadDate. If I click the close button on the main form and I look at my recordsource table, a record with the date that was last selected from the ActiveX calendar has been created...Why? I didn't tell it to save?

Thanks in advance for your help!!
Joseph
Hi,

Don't make me out to be Bill G or something, but that's not a bug, it's a feature!

Access "saves" on the fly. Whenever you close a form, or do anything that would require the underlying recordset to be modified, Access does it for you. There are several ways around this, but you have to know what you want to do with your data (or what you want your users to do with their data).

Please feel free to post further here with what you want to happen and why. We'll get you on the right path.

Jim
Mar 3 '08 #2
jmarcrum
105 New Member
Hi,

Don't make me out to be Bill G or something, but that's not a bug, it's a feature!

Access "saves" on the fly. Whenever you close a form, or do anything that would require the underlying recordset to be modified, Access does it for you. There are several ways around this, but you have to know what you want to do with your data (or what you want your users to do with their data).

Please feel free to post further here with what you want to happen and why. We'll get you on the right path.

Jim
Hey thanks for the reply Jim!

The two textboxes (txtVerses and txtDate) have control sources to a certain table. The user uses this subform to assign a reading to a certain member of the church on a certain day (the day is always a Sunday). But I give the user the opportunity to select which Sunday via the calendar tool. When they click a day on the calendar, i have code that makes that day appear in the txtDate textbox.

What I'm finding out is that the subform isn't error proof. If the user opens the Main form frmAssignDuties...the subform frmAssignReading is also on it down at the bottom. If the user wants to "have some fun" and click around like crazy on the calendar, just to see the date change, and then close the Main form without selecting AM or PM in the Time combo box or selecting a Member in the Member combo box, or typing in a set of assigned Bible verses to read (on that date, at that time, for that member) in the verses textbox...not even clicking SAVE...an empty record will be created and added to the table with just a date showing!

I don't want that.

Thanks again,
Joseph
Mar 3 '08 #3
FishVal
2,653 Recognized Expert Specialist
Hi, Joseph.

Please post code opening the form with calendar control and code handling Click event of your buttons. So far we know only that the buttons have captions Save and Cancel. Very helpful but not enough ;).

Kind regards,
Fish
Mar 3 '08 #4
jmarcrum
105 New Member
Hi, Joseph.

Please post code opening the form with calendar control and code handling Click event of your buttons. So far we know only that the buttons have captions Save and Cancel. Very helpful but not enough ;).

Kind regards,
Fish
Hey FishVal!

Thanks for your post!

Here's my code...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Calendar_Click()
  2.     'transfer the date chosen in the calendar to cmbDate
  3.     txtDate.SetFocus
  4.     txtDate.Text = Calendar.Value
  5. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdCancel_Click()
  2.     'Cancel proposed changes
  3.     Me.Undo
  4. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSaveClose_Click()
  2. '*************************************************************'
  3. 'Author: Joseph                               '
  4. 'Date: 3/2/2008                                               '
  5. 'Desc: Assign a Reading to a member                           '
  6. 'Modifications:                                               '
  7. 'Date       By Who      Desc                                  '
  8. '                                                             '
  9. '*************************************************************'
  10.  
  11. Dim Member As String
  12. Dim Time As String
  13. Dim Verses As String
  14. Dim message As String
  15.  
  16. txtVerses.SetFocus
  17. Verses = txtVerses.Text
  18.  
  19. cmbTime.SetFocus
  20. Time = cmbTime.Text
  21.  
  22. cmbMember.SetFocus
  23. Member = cmbMember.Text
  24.  
  25. If Verses = "" Then
  26.     message = "Verses"
  27. End If
  28.  
  29. If Member = "" Then
  30.     If message = "" Then
  31.         message = "Member"
  32.     Else
  33.         message = message & ", Member"
  34.     End If
  35. End If
  36.  
  37. If Time = "" Then
  38.     If message = "" Then
  39.         message = "Time"
  40.     Else
  41.         message = message & ", Time"
  42.     End If
  43. End If
  44.  
  45. 'If message is not blank, tell the user to enter the fields in the message
  46. If message <> "" Then
  47.     message = "Please enter the following fields: " & message
  48.     MsgBox message
  49.     Exit Sub
  50. End If
  51.  
  52. 'Make sure the Reading has not already been assigned to the member
  53. If ReadingExists(Me.cmbTime.Value, Me.txtDate.Value) Then
  54.     MsgBox "This Reading has already been assigned."
  55.     Exit Sub
  56. End If
  57.  
  58. 'Save the Record
  59. DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  60.  
  61. 'clear the values for new entry
  62. txtVerses.SetFocus
  63. txtVerses.Text = ""
  64.  
  65. cmbTime.SetFocus
  66. cmbTime.Text = ""
  67.  
  68. cmbMember.SetFocus
  69. cmbMember.Text = ""
  70.  
  71. txtVerses.SetFocus
  72.  
  73. Exit Sub
  74.  
  75. End Sub
  76.  
  77. Public Function ReadingExists(TimeID As Integer, ReadDate As String) As Boolean
  78. '*************************************************************'
  79. 'Author: Joseph                              '
  80. 'Date: 3/2/2008                                               '
  81. 'Desc: Returns True if Reading passed in exists in            '
  82. '      tblRead; False otherwise                               '
  83. 'Modifications:                                               '
  84. 'Date       By Who      Desc                                  '
  85. '                                                             '
  86. '*************************************************************'
  87. Dim strSQL As String
  88. Dim dbs_curr As Database
  89. Dim record As Recordset
  90.  
  91. Set dbs_curr = CurrentDb
  92.  
  93. strSQL = "SELECT tblRead.* FROM tblRead WHERE (((tblRead.TimeID)=" & TimeID & ") AND ((tblRead.ReadDate)='" & ReadDate & "'));"
  94. Set record = dbs_curr.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges, dbOptimistic)
  95.  
  96. If Not record.EOF Then
  97.     ReadingExists = True
  98. Else
  99.     ReadingExists = False
  100. End If
  101.  
  102. End Function
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.     Calendar.Value = Now()
  3. End Sub
Mar 3 '08 #5
FishVal
2,653 Recognized Expert Specialist
Ok. I will look at your code as soon as I get home.

Just a quick question. Why did you place calendar control to a subform on the main form? Is it less suitable to place it on the main form as soon as it should be linked to the main form recordsource?

Additionally, I would discourage you from assigning default value by modifying field on form load - this immediately creates a new record, assigning default value for table field or form control is much more suitable.

One more point - if you use Now() function you should be aware that it returns time portion as well as date. If the values are expected to treat as dates only you'd better use Date() function to prevent future troubles with dates comparing
e.g.
#1/1/1#=#1/1/1# returns False just because
the first is #1/1/1 12:00:00#
and the second is #1/1/1 12:00:01#

Regards,
Fish
Mar 3 '08 #6
Denburt
1,356 Recognized Expert Top Contributor
It sounds like you need some validation checks put in place either in the form close event or in the table itself so if a field in the table is mandatory then you can't create the record unless that field is filled in.
If you use the on close event and not a table restriction the if the validation fails you can use something like the following.

if isnull(me!SomeField) or len(trim(me!SomeField) = 0 then
me.undo
end if
Mar 3 '08 #7

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

Similar topics

3
by: Wim Roffil | last post by:
Hi, When I do a select with a limit I get always the same records. Usually this is the desidered effect. But now I want to do a random select. So every time I do a select I should get a...
5
by: Mal | last post by:
Hello. I have a database that tracks reservations at a campground. I want to be able to make a calendar type report that shows how many people are here in given period. Stored for each...
8
by: Shyguy | last post by:
Is it possible to create a calendar that shows previous input data and also allows for input of new data?
1
by: EV | last post by:
We have put a calendar control on a form. The form is for employee time off. The user chooses the employee and the type of time off (sick, comp, vacation, etc)...then clicks on the calendar to...
4
by: yf | last post by:
A KB article "http://support.microsoft.com/default.aspx?scid=kb;en-us;209599" tells that the maximum number of records that a table may hold if the PRIMARY key data type is set to AUTONUMBER is...
0
by: maxrawson | last post by:
First, let me start by saying my asp.net experience is still in it's infancy so please bare with me as I try to explain my situation. I have created a single page that with the use of many...
2
by: Caesar Augustus | last post by:
First, let me start by saying my asp.net experience is still in it's infancy so please bare with me as I try to explain my situation. I have created a single page that with the use of many...
9
by: Greg | last post by:
Hi, I have a table with "dates", i'd like to display those dates on a calendar. I've put a calendar in a form, linked to my "date" field, and it works, but only showing one "date" per calendar....
2
by: cdawley4 | last post by:
Hi, I am trying to decide what would be the best program to start a vacation selection calendar in. I am in a group of 60 employees and the current software we have, which I believe is written...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.