adding calendar to form

  • Thread starter Thread starter fleart1
  • Start date Start date
F

fleart1

Guest
Relatively new to programming and trying to insert the calendar to a form. I copied code down exactly as sample said. Now problem is this. I have the procedure in correct place with the functin below

Private Sub Calendar_Click()
Table!date.Value = Forms!Form_EntryForm!calendar.Value
End Sub

I have a field called date in a database that this form is in. When I click the date, the date in the database is supposed to change but I get an error with the above code. Can anybody tell me what I am doing wrong?
thanks :confused:
 
Don't use reserved words (Date is a reserved word) as field headings. Access doesn't like that and you will experience things such as you are experiencing now.
 
Assuming that the calendar control and date field are both on the same form , try using
Private Sub Calendar_Click()
me![date] = me![calendar]
End Sub

HTH

Peter
 
But whatever you do, still rename your field from "Date" to something that isn't a reserved word in Access. You'll come to appreciate it later.
 
I changed date to adate and inserted exactly what you have above with adate instead of date but got exact same error
"access cant find the field 'adate' referred to in your expression.
 
Put a textbox on the form and make it's visible property "False." Also, bind it to the field in the table that you want updated by the calendar.

Then, put this code in the click event of the calendar:

Code:
Private Sub Calendar_Click()
Me.PutTextBoxNameHere = Me.PutCalendarControlNameHere.Value
End Sub

If the form you are updating is NOT the same form where the calendar control is on, then you will have to use the Forms!formname.Calendar.Value referencing way. If both the textbox and caldendar control are on the same form, then the method shown in the code window above should work.
 
Calendar Controls

I am at the stage of some of the above people and have been looking at all the info available.

I have a Form 'FrmCompanies' with a field called 'TextBoxNextCallDue' Relating to a table field 'NextCalldue' in TblCompanies

I have a Form 'FrmNextCallDue' With a Calendar Control called 'CalNextCallDue'

I have a button on FromCompanies which opens Form FrmNextCallDue and want to click a date on the calendar, which when updated and closed will update the FromCompanies text box. I originally thought that using a text box oin the same form to fill with a date and then using SQL INSERT INTO might work but am going round in circles trying to get a calendar control to update a text box on the same form!

Try as I might using the references and information and links from this message posting am unable to get the thing to work. For example; it is mentioned in the posting from bob that the event should run from a mouse click but that is not an option in the calendar event list! None of the others seem to work as expected.

(Access 2003)

Please Heeeeelp
 
Thanks....Further Error "Date"

Thanks and like others have follwed instructions to the letter but the common error I get with all the different ways is when clicking the button, or firing off the process, a Debug window pops up with the module etc, the first line is always highlighted yellow and the cursor stops at the end of the last word, Date. Any advice?

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Form_Open_Err

'Initialize to the existing date, or today if null.
If IsDate(NextCallDue) Then
Me.txtDate = NextCallDue.Value
Else
Me.txtDate = Date
 
If referring to the field:
Code:
If IsDate(Me!NextCallDue) Then
If referring to the textbox:
Code:
If IsDate(Me.NextCallDue) Then

But you should really rename your controls to not have the same name as the textbox as it helps keep ambiguity away.
 
very weird...

Thanks for the reply, still confused though as when change . for a ! I get n error but different ones. with me.nextcalldue the compiler stops highlighting nextcalldue but with me!nextcalldue the compiler stops highlighting date at the end??...

Private Sub cmdMonthUp_Click()
Call SetDate("M", 1)
End Sub

Private Sub cmdOk_Click()
On Error Resume Next
'Purpose: Transfer the result back to the calling text box (if there is one), and close.

If NextCallDue = Me!NextCallDue Then
'do nothing
Else
NextCallDue = Me!NextCallDue
End If
NextCallDue.SetFocus
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub

Private Sub cmdYearDown_Click()
Call SetDate("YYYY", -1)
End Sub
Private Sub cmdYearUp_Click()
Call SetDate("YYYY", 1)
End Sub

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Form_Open_Err

'Initialize to the existing date, or today if null.
If IsDate(NextCallDue) Then
Me!NextCallDue = NextCallDue.Value
Else
Me!NextCallDue = Date
End If
 
Can you post a screenshot of the code while it is highlighted? I'm not so sure I'm imagining where you are talking about. Also, what is the SetDate function you are calling?
 
Heres a couple of screenshots

Attachting a view of the code and a few of my windows.
 

Attachments

  • capture.jpg
    capture.jpg
    22.6 KB · Views: 747
  • capture2.jpg
    capture2.jpg
    27.5 KB · Views: 446
Unfortunately your screenshots are too small. I can't read any of it. I tried saving and opening with Photo Editor to magnify but it blurs out.
 
bigger examples

had to chance capture settinfs due to filesize upload limits. these should be better,

the two examples show vb window opens after clicking the calender box on my form with the error message shown. then capture001 after clicking ok on the error message window.
 

Attachments

  • capture000.gif
    capture000.gif
    90.2 KB · Views: 269
  • capture001.gif
    capture001.gif
    86.6 KB · Views: 228
If you're getting the error on Date like it looks like, it's highly likely that you are suffering from a MISSING Reference. Go to Tools > References and check to see if any say MISSING. If so, uncheck them, close the database and reopen it.
 
I Think I Found The Answer

Every time access has been opening i have been seeing a message "Database Name" 2your database or project contains a missing or broken link to the file 4TXLIM10.MDA" to ensure that your database or project works correctly, you must fix this reference

In a new vba window i used 'Tools' & 'References' and unchecked this reference and since then I do not seem to have the same trouble as described in previous threads.

very weird!

Thanks, your hit was the answer!
 

Users who are viewing this thread

Back
Top Bottom