Calendar inuser form
-
QUESTION: I know very little VB and I need a little bit of help on this issue, please. I have a calendar in my user form. It sets the date to the active cell. However, I have other text boxes for data, then at the end I have a save button, that saves all the data in the next empty row of data. How can I have the calendar date picked go to the next empty row along with the other data. Below is my current script: Private Sub Calendar1_Click() ActiveCell = Calendar1.Value Calendar1.Value = Date ActiveCell.NumberFormat = "mm/dd/yy" End Sub ____________ Private Sub cmdAdd_Click() Dim IRow As Long Dim iclass As Long Dim ws As Worksheet Set ws = Worksheets("Work Assignment") Me.Calendar1.Value = Date 'find first empty row in database IRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row With ws .Cells(IRow, 1).Value = Me.Calendar1.Value .Cells(IRow, 2).Value = Me.cboClass.Value .Cells(IRow, 20).Value = Me.cboClass.List(iclass, 1) .Cells(IRow, 3).Value = Me.Monday.Value .Cells(IRow, 4).Value = Me.Tuesday.Value .Cells(IRow, 5).Value = Me.Wednesday.Value .Cells(IRow, 6).Value = Me.Thursday.Value .Cells(IRow, 7).Value = Me.Friday.Value .Cells(IRow, 8).Value = Me.Notes.Value End With 'clear the data Me.cboClass.Value = "" Me.Calendar1.Value = "" Me.cboClass.Value = "" Me.Monday.Value = "" Me.Tuesday.Value = "" Me.Wednesday.Value = "" Me.Thursday.Value = "" Me.Friday.Value = "" Me.Notes.Value = "" Me.Calendar1.SetFocus End Sub Thank you for any help you can provide! ANSWER: Susan, You already have the code to do what you ask Cells(IRow, 1).Value = Me.Calendar1.Value puts the date in column A. Perhaps you just need code to format the value as a date Cells(IRow, 1).Value = Me.Calendar1.Value Cells(IRow, 1).Numberformat = "mm/dd/yyyy" --- Now in the click event of the calendar control you have this code. Private Sub Calendar1_Click() ActiveCell = Calendar1.Value Calendar1.Value = Date ActiveCell.NumberFormat = "mm/dd/yy" End Sub But I am not sure what you are trying to do with that. ---------- FOLLOW-UP ---------- QUESTION: Thanks for the quick reply! The click event for the calendar is to capture the date selected. I removed this code, and it only writes todays date to my data set. It doesn't capture the date I select on the calendar. If I keep the code, it writes the date I select, but I can't copy it into my data set. Do you have any suggestions?
-
Answer:
Susan, this code fires when you change the date: Private Sub Calendar1_Click() ActiveCell = Calendar1.Value Calendar1.Value = Date ActiveCell.NumberFormat = "mm/dd/yy" end sub It writes the date that was selected in the activecell wherever that may be it sets the calendar controls date to today if formats the activecell as a date in mm/dd/yy format There is no reason to have that code that I can see unless you want the date selected written to the activecell. If so, then why change the control to today's date. remove that line. Private Sub Calendar1_Click() ActiveCell = Calendar1.Value ActiveCell.NumberFormat = "mm/dd/yy" end sub Now you don't change the date in the calendar control to today's date in your code. But you say without that click event, it writes todays date with your data. I would suspect that is because you have this line of code in your command button click routine: Me.Calendar1.Value = Date that line should be removed. so the new code would be: Private Sub cmdAdd_Click() Dim IRow As Long Dim iclass As Long Dim ws As Worksheet Set ws = Worksheets("Work Assignment") 'Me.Calendar1.Value = Date <== commented out 'find first empty row in database IRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row With ws .Cells(IRow, 1).Value = Me.Calendar1.Value .Cells(IRow, 1).NumberFormat = "mm/dd/yyyy" .Cells(IRow, 2).Value = Me.cboClass.Value .Cells(IRow, 20).Value = Me.cboClass.List(iclass, 1) .Cells(IRow, 3).Value = Me.Monday.Value .Cells(IRow, 4).Value = Me.Tuesday.Value .Cells(IRow, 5).Value = Me.Wednesday.Value .Cells(IRow, 6).Value = Me.Thursday.Value .Cells(IRow, 7).Value = Me.Friday.Value .Cells(IRow, 8).Value = Me.Notes.Value End With 'clear the data Me.cboClass.Value = "" Me.Calendar1.Value = "" Me.cboClass.Value = "" Me.Monday.Value = "" Me.Tuesday.Value = "" Me.Wednesday.Value = "" Me.Thursday.Value = "" Me.Friday.Value = "" Me.Notes.Value = "" Me.Calendar1.SetFocus End Sub That answer is based on what I can see from what you have posted. I believe it should now do what you want. (I don't believe you actually need the Click for the calendar)
Miningco.com Visit the source
Related Q & A:
- How To Download Kalnirnay Calendar?Best solution by download.cnet.com
- How To Create An Online Calendar?Best solution by Stack Overflow
- How to add calendar events in other calendar in Android?Best solution by Stack Overflow
- How to add calendar event in Yahoo calendar?Best solution by Stack Overflow
- How do I sync my blackberry calendar to my Google calendar?Best solution by Quora
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.