PC Review


Reply
 
 
Patrick C. Simonds
Guest
Posts: n/a
 
      22nd Nov 2008
The user inputs a year Value to TextBox1. How can I amend the code below so
that January 1 of the year is inputted to into the cell?




Private Sub CommandButton1_Click()

Dim rng
Set rng = Cells(ActiveCell.Row, 1)

rng(1, 2).Value = TextBox1.Value

Module2.Rename_Worksheets
Unload Year

End Sub

 
Reply With Quote
 
 
 
 
Ron Rosenfeld
Guest
Posts: n/a
 
      22nd Nov 2008
On Sat, 22 Nov 2008 10:26:30 -0800, "Patrick C. Simonds"
<(E-Mail Removed)> wrote:

>The user inputs a year Value to TextBox1. How can I amend the code below so
>that January 1 of the year is inputted to into the cell?
>
>
>
>
>Private Sub CommandButton1_Click()
>
>Dim rng
>Set rng = Cells(ActiveCell.Row, 1)
>
>rng(1, 2).Value = TextBox1.Value
>
>Module2.Rename_Worksheets
>Unload Year
>
>End Sub


Use the DateSerial function

For example:

rng(1, 2).Value = DateSerial(TextBox1.Value,1,1)
--ron
 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      22nd Nov 2008
If you want it as a date:

rng(1, 2) = CDate("January 1, " & TextBox1.Value)

If you want it as text:

rng(1, 2) = "January 1, " & TextBox1.Value





"Patrick C. Simonds" wrote:

> The user inputs a year Value to TextBox1. How can I amend the code below so
> that January 1 of the year is inputted to into the cell?
>
>
>
>
> Private Sub CommandButton1_Click()
>
> Dim rng
> Set rng = Cells(ActiveCell.Row, 1)
>
> rng(1, 2).Value = TextBox1.Value
>
> Module2.Rename_Worksheets
> Unload Year
>
> End Sub
>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      22nd Nov 2008
I bet that excel will see that "text" entry and parse it as a date.

If I wanted text, I'd use:
rng(1, 2) = "'January 1, " & TextBox1.Value '<-- with leading apostrophe

But I'd be more inclined to use:

with rng(1, 2)
.numberformat = "mm/dd/yyyy"
if isnumeric(me.textbox1.value) then
.value = dateserial(me.textbox1.value, 1, 1)
end if
end with

or for text:

with rng(1, 2)
.numberformat = "@"
if isnumeric(me.textbox1.value) then
.value = "January 1, " & me.textbox1.value
end if
end with

(Maybe even add some more validity checks, too.)



JLGWhiz wrote:
>
> If you want it as a date:
>
> rng(1, 2) = CDate("January 1, " & TextBox1.Value)
>
> If you want it as text:
>
> rng(1, 2) = "January 1, " & TextBox1.Value
>
> "Patrick C. Simonds" wrote:
>
> > The user inputs a year Value to TextBox1. How can I amend the code below so
> > that January 1 of the year is inputted to into the cell?
> >
> >
> >
> >
> > Private Sub CommandButton1_Click()
> >
> > Dim rng
> > Set rng = Cells(ActiveCell.Row, 1)
> >
> > rng(1, 2).Value = TextBox1.Value
> >
> > Module2.Rename_Worksheets
> > Unload Year
> >
> > End Sub
> >
> >


--

Dave Peterson
 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      22nd Nov 2008
Probably so, depending on how he has the range formatted. But I had variable
assignment in mind when I wrote that.

"Dave Peterson" wrote:

> I bet that excel will see that "text" entry and parse it as a date.
>
> If I wanted text, I'd use:
> rng(1, 2) = "'January 1, " & TextBox1.Value '<-- with leading apostrophe
>
> But I'd be more inclined to use:
>
> with rng(1, 2)
> .numberformat = "mm/dd/yyyy"
> if isnumeric(me.textbox1.value) then
> .value = dateserial(me.textbox1.value, 1, 1)
> end if
> end with
>
> or for text:
>
> with rng(1, 2)
> .numberformat = "@"
> if isnumeric(me.textbox1.value) then
> .value = "January 1, " & me.textbox1.value
> end if
> end with
>
> (Maybe even add some more validity checks, too.)
>
>
>
> JLGWhiz wrote:
> >
> > If you want it as a date:
> >
> > rng(1, 2) = CDate("January 1, " & TextBox1.Value)
> >
> > If you want it as text:
> >
> > rng(1, 2) = "January 1, " & TextBox1.Value
> >
> > "Patrick C. Simonds" wrote:
> >
> > > The user inputs a year Value to TextBox1. How can I amend the code below so
> > > that January 1 of the year is inputted to into the cell?
> > >
> > >
> > >
> > >
> > > Private Sub CommandButton1_Click()
> > >
> > > Dim rng
> > > Set rng = Cells(ActiveCell.Row, 1)
> > >
> > > rng(1, 2).Value = TextBox1.Value
> > >
> > > Module2.Rename_Worksheets
> > > Unload Year
> > >
> > > End Sub
> > >
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      22nd Nov 2008
I don't understand what a variable assignment means.

JLGWhiz wrote:
>
> Probably so, depending on how he has the range formatted. But I had variable
> assignment in mind when I wrote that.
>
> "Dave Peterson" wrote:
>
> > I bet that excel will see that "text" entry and parse it as a date.
> >
> > If I wanted text, I'd use:
> > rng(1, 2) = "'January 1, " & TextBox1.Value '<-- with leading apostrophe
> >
> > But I'd be more inclined to use:
> >
> > with rng(1, 2)
> > .numberformat = "mm/dd/yyyy"
> > if isnumeric(me.textbox1.value) then
> > .value = dateserial(me.textbox1.value, 1, 1)
> > end if
> > end with
> >
> > or for text:
> >
> > with rng(1, 2)
> > .numberformat = "@"
> > if isnumeric(me.textbox1.value) then
> > .value = "January 1, " & me.textbox1.value
> > end if
> > end with
> >
> > (Maybe even add some more validity checks, too.)
> >
> >
> >
> > JLGWhiz wrote:
> > >
> > > If you want it as a date:
> > >
> > > rng(1, 2) = CDate("January 1, " & TextBox1.Value)
> > >
> > > If you want it as text:
> > >
> > > rng(1, 2) = "January 1, " & TextBox1.Value
> > >
> > > "Patrick C. Simonds" wrote:
> > >
> > > > The user inputs a year Value to TextBox1. How can I amend the code below so
> > > > that January 1 of the year is inputted to into the cell?
> > > >
> > > >
> > > >
> > > >
> > > > Private Sub CommandButton1_Click()
> > > >
> > > > Dim rng
> > > > Set rng = Cells(ActiveCell.Row, 1)
> > > >
> > > > rng(1, 2).Value = TextBox1.Value
> > > >
> > > > Module2.Rename_Worksheets
> > > > Unload Year
> > > >
> > > > End Sub
> > > >
> > > >

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      22nd Nov 2008
Playing semantics? <g>

myDate = "January 1, " & TextBox1.Value

is a variable assignment. A value is assigned to a variable. You knew what
I meant.

"Dave Peterson" wrote:

> I don't understand what a variable assignment means.
>
> JLGWhiz wrote:
> >
> > Probably so, depending on how he has the range formatted. But I had variable
> > assignment in mind when I wrote that.
> >
> > "Dave Peterson" wrote:
> >
> > > I bet that excel will see that "text" entry and parse it as a date.
> > >
> > > If I wanted text, I'd use:
> > > rng(1, 2) = "'January 1, " & TextBox1.Value '<-- with leading apostrophe
> > >
> > > But I'd be more inclined to use:
> > >
> > > with rng(1, 2)
> > > .numberformat = "mm/dd/yyyy"
> > > if isnumeric(me.textbox1.value) then
> > > .value = dateserial(me.textbox1.value, 1, 1)
> > > end if
> > > end with
> > >
> > > or for text:
> > >
> > > with rng(1, 2)
> > > .numberformat = "@"
> > > if isnumeric(me.textbox1.value) then
> > > .value = "January 1, " & me.textbox1.value
> > > end if
> > > end with
> > >
> > > (Maybe even add some more validity checks, too.)
> > >
> > >
> > >
> > > JLGWhiz wrote:
> > > >
> > > > If you want it as a date:
> > > >
> > > > rng(1, 2) = CDate("January 1, " & TextBox1.Value)
> > > >
> > > > If you want it as text:
> > > >
> > > > rng(1, 2) = "January 1, " & TextBox1.Value
> > > >
> > > > "Patrick C. Simonds" wrote:
> > > >
> > > > > The user inputs a year Value to TextBox1. How can I amend the code below so
> > > > > that January 1 of the year is inputted to into the cell?
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Private Sub CommandButton1_Click()
> > > > >
> > > > > Dim rng
> > > > > Set rng = Cells(ActiveCell.Row, 1)
> > > > >
> > > > > rng(1, 2).Value = TextBox1.Value
> > > > >
> > > > > Module2.Rename_Worksheets
> > > > > Unload Year
> > > > >
> > > > > End Sub
> > > > >
> > > > >
> > >
> > > --
> > >
> > > Dave Peterson
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      23rd Nov 2008
I didn't understand your point. I thought you were answering the question about
putting the date into the cell--not creating a string variable and populating
that with a value.

But I understand what you mean now <bg>.

JLGWhiz wrote:
>
> Playing semantics? <g>
>
> myDate = "January 1, " & TextBox1.Value
>
> is a variable assignment. A value is assigned to a variable. You knew what
> I meant.
>
> "Dave Peterson" wrote:
>
> > I don't understand what a variable assignment means.
> >
> > JLGWhiz wrote:
> > >
> > > Probably so, depending on how he has the range formatted. But I had variable
> > > assignment in mind when I wrote that.
> > >
> > > "Dave Peterson" wrote:
> > >
> > > > I bet that excel will see that "text" entry and parse it as a date.
> > > >
> > > > If I wanted text, I'd use:
> > > > rng(1, 2) = "'January 1, " & TextBox1.Value '<-- with leading apostrophe
> > > >
> > > > But I'd be more inclined to use:
> > > >
> > > > with rng(1, 2)
> > > > .numberformat = "mm/dd/yyyy"
> > > > if isnumeric(me.textbox1.value) then
> > > > .value = dateserial(me.textbox1.value, 1, 1)
> > > > end if
> > > > end with
> > > >
> > > > or for text:
> > > >
> > > > with rng(1, 2)
> > > > .numberformat = "@"
> > > > if isnumeric(me.textbox1.value) then
> > > > .value = "January 1, " & me.textbox1.value
> > > > end if
> > > > end with
> > > >
> > > > (Maybe even add some more validity checks, too.)
> > > >
> > > >
> > > >
> > > > JLGWhiz wrote:
> > > > >
> > > > > If you want it as a date:
> > > > >
> > > > > rng(1, 2) = CDate("January 1, " & TextBox1.Value)
> > > > >
> > > > > If you want it as text:
> > > > >
> > > > > rng(1, 2) = "January 1, " & TextBox1.Value
> > > > >
> > > > > "Patrick C. Simonds" wrote:
> > > > >
> > > > > > The user inputs a year Value to TextBox1. How can I amend the code below so
> > > > > > that January 1 of the year is inputted to into the cell?
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Private Sub CommandButton1_Click()
> > > > > >
> > > > > > Dim rng
> > > > > > Set rng = Cells(ActiveCell.Row, 1)
> > > > > >
> > > > > > rng(1, 2).Value = TextBox1.Value
> > > > > >
> > > > > > Module2.Rename_Worksheets
> > > > > > Unload Year
> > > > > >
> > > > > > End Sub
> > > > > >
> > > > > >
> > > >
> > > > --
> > > >
> > > > Dave Peterson
> > > >

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what method to use to add 1 day to a date (hotel reservation for one night by clicking on calender) and get it displayed in date formate in a textbox for departure date? Amanda Microsoft VB .NET 2 10th Oct 2006 06:52 AM
Link date to a table with Date Range (Eff Date and term date) =?Utf-8?B?S2V2aW4gUmVlZA==?= Microsoft Access 1 31st Aug 2006 04:23 PM
i have two date fileds Opend date Due date, can i set default on due date so, its always = to open date on my data entry form1 Urgent Mike Saifie Microsoft Access Form Coding 1 9th Mar 2006 01:08 AM
Run Query from date to date, Print the from date to date in the header of the report? Dustin Swartz Microsoft Access Queries 1 25th Jan 2005 07:06 PM
Date fields automatically changing when today date matches date field entry.Help! Brian Cassin Microsoft Access Forms 1 15th Nov 2003 01:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:48 AM.