Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Only Allow Date Format In Userform Textbox


Hello!

I'd like to edit my textbox in a userform to only allow date entries (yyyy.mm.dd), and generate an error message, if anything else is entered into it.
Can anyone help me with altering the code?


Code:
Private Sub CommandButton1_Click() 'Add button
Sheets(1).Activate
Nextrow = Application.WorksheetFunction.CountA(Range("A:A")) + 2
If TextName.Text = "" Then 'Textbox for name entry
MsgBox "You must enter a name."
TextName.SetFocus
Exit Sub
ElseIf TextDate.Text = "" Then 'Textbox for date entry
MsgBox "You must enter a date."
TextDate.SetFocus
Exit Sub
End If
Cells(Nextrow, 1) = TextName.Text
Cells(Nextrow, 2) = TextDate.Text
Cells(Nextrow, 3) = TextText.Text

TextName.Text = ""
TextDate.Text = ""
TextText.Text = ""
TextName.SetFocus
End Sub

Private Sub CommandButton2_Click() 'Exit button
Unload Me
End Sub
Edit by italkid: No need to colour your code, just use the [vb]][ and [/vb] tags to display your code...




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
UserForm: Date Format In TextBox
Hi

I have done a user form on Visual Basic for Excel v6.0

I have a few Text Boxes to obtain data from the users

Firstly, I do not know how to format the text that the user can input in the Text Box

Secondly, two of the boxes will be used for dates. The first one automatically formatted the data entered as a date but the second is in a text format.

Does anyone have any suggestions for the above.

Thanks for the help

Sasm

Looking For A Specifi Format In A Userform Textbox
Guys,
Is there a way to test a textbox in a userform that has to contain two letters and 5 numbers together, in that order otherwise fail. this is what I have been trying however it has not been working for me. I would love any help on this one. Thanks in advance!!


Code:
Private Sub id_number_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim s_num As String
s_num = id_number
If s_number = "" Then
s_num = MsgBox(Title:="Alert", Prompt:="Please Enter A AlphaNumeric Value1.", Buttons:=vbOKOnly + vbExclamation)
If s_num = vbOK Then Cancel = True
End If
'If s_num <> "??#####" Then
' s_num = MsgBox(Title:="Alert", Prompt:="Please Enter A AlphaNumeric Value2.", Buttons:=vbOKOnly + vbExclamation)
' If s_num = vbOK Then Cancel = True
'Else
'Worksheets("consultant").Range("a2").Value = said_num
'End If
If IsNumeric(s_number) And id_number.TextLength <= 7 Then
s_num = MsgBox(Title:="Alert", Prompt:="Please Enter A AlphaNumeric Value3.", Buttons:=vbOKOnly + vbExclamation)
If s_num = vbOK Then Cancel = True
End If
If Not IsNumeric(id_number) And id_number.TextLength <= 7 Then
s_num = MsgBox(Title:="Alert", Prompt:="Please Enter A AlphaNumeric Value4.", Buttons:=vbOKOnly + vbExclamation)
If s_num = vbOK Then Cancel = True
End If
'If IsNumeric(s_num) Then
' s_num = MsgBox(Title:="Alert!", Prompt:="Please Enter Your ID1.", Buttons:=vbOKOnly + vbExclamation)
' If s_num = vbOK Then Cancel = True
' End If
'If Not IsNumeric(s_num) Then
' s_num = MsgBox(Title:="Alert!", Prompt:="Please Enter Your ID2.", Buttons:=vbOKOnly + vbExclamation)
' If s_num = vbOK Then Cancel = True
'End If
'If id_number.Value Like "#?" Then
' s_num = MsgBox(Title:="Alert!", Prompt:="Please Enter Your ID3.", Buttons:=vbOKOnly + vbExclamation)
' If s_num = vbOK Then Cancel = True
'E'nd If
'Else
'If id_number.Text = "??#####" Then
' Worksheets("consultant").Range("a2").Value = s_num
' End If
End Sub

Format Text Style Etc In Userform/textbox
Hi.

In a textbox in a userform is it possible to select text and then press a commandbutton to format the selected text, eg centre justify, or make red etc etc (a button would be used for each style)?

ie, text is entered into a textbox, can it then be modified by clicking on buttons etc to justify, and will that textbox be viewed as it was edited at a later time.

If you start to go on about private_ etc and so on you may lose me. My knowledge is limited to formulae and basic userform programming (ie things similar to normal vb coding).

Any suggestions welcome.

Thanks

PS. I am using Excel 2000.

Date Format And Textbox
I use a textbox to get a date from the user, but when i use this date in the programme it's taken as US format of "mm/dd/yy"
Does anyone know how to change this to UK format "dd/mm/yy"?

Thanks

Textbox Date Format
I'm a newbie here and I'm new to VB as well
Can some 1 pls answer the following question for me.

I have a VB form, when the form initializes, I want the textbox on that form to have the current date ... the problem I have is its in US format. and I want to have it in UK format "DD/MM/YYYY". I want to be able to enter any date valid date, past or present, but in UK format and I also want to validate the date as well. Finally, when I press a button (in my case add button) on the form, I want that date to add to a cell on an excel sheet and that cell also should have the date in UK format. Can some 1 be kind enough the help a poor soul. pls give me the code for both textbox and excel sheet.

I tried the following pieces of code ... but no joy

(a) TextBox1.Text = Date

(b) TextBox1.Text = DatePart("d", Date) & "/" & DatePart("m", Date) & "/" & DatePart("yyyy", Date)

(c) Dim dt As Date
dt = Date
Format dt, "dd mm yyyy"
TextBox1.Text = dt

where "TextBox1" is the name of textbox

Thx in Advance

Format Date In Textbox
anyone know how to format the date ina text box so that if the person entering the date types 190368 it will convert it to 19/03/1968.

tryed it with the masked but had no luck


thx

Textbox Date Format
Can anyone tell me how to format a textbox so that when it gets focus and loses focus that it gets the mask for the short date, "dd,mm,yyyy", that someone will enter?? I need help with this easy one. Thanks.

Date Format Input In Textbox
a few years ago, i post a thread regarding about this topic
and was successful in obtaining a code for this
Since the whole forum was formatted, i was not able to find the same post that i had posted a few years ago

This thread was about inputting a date in the format of "dd/mm/yyyy"
an editmaskbox was not used
It was like in the Keypress event where isnumeric was used
and Left() and Right() function were used
It also had the value inputted from the Now() in form_load event
When the user press a number value, that value is insert and input over the current value

For example,

in the textbox1.text, "01/12/2003" and the cursor is at the beginning
the user press 3
the textbox1.text will be "31/12/2003"
the user press 0
the textbox1.text will be "30/12/2003"
the user press 1
the textbox1.text will be "30/12/2003"
the user press 1
the textbox1.text will be "30/11/2003"
the user press enter
the textbox1 will lose focus
of cuz it is already in the keypress event
where Keyascii = 13
object2.setforcu

How Can I Change The Date Format In A Textbox?
Dear Friends,

Suppose if I enter the date like this : 15/05/2007 and want the textbox to automatically change it to 15 May 2007 what code to be written in textbox's lostfocus event?

Thanks in advance.

vblearner6

[RESOLVED With Thanks] - Date Format In Preformatted Textbox Or Similar --&gt; 'dd/mm/yyyy'
Hi,

I need some help. I want a textbox preformatted for entering the date, i.e. the textbox would show dd/mm/yyyy with the '/' separator symbol.

On clicking the textbox, the 'dd' gets highlighted, so I enter the date, the cursor Automatically moves past the '/' separator symbol and highlight 'mm' etc.

I have seen this type of textbox/editbox done in Borland C++ Builder, and was wondering whether something similar is possible in VB 6.

Any assistance would be much appreciated.


Thanks, Ash

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

                                    **** KNOWLEDGE IS LIMITLESS ! ****
    **** FOR EVERY KNOWLEDGEABLE, THERE EXISTS A MORE KNOWLEDGEABLE ! ****

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Edited by - mchu6am4 on 9/23/2004 9:29:47 AM

Change Short Date Format To Long Date Format (windows Api?)
i want that when i load my program, it will change the date settings in my computer (short date to long date). How can i do that?

DATE Problems - Change Date Format To European, Get Current Date, Subtract 2 Dates?
Need someone to point me in the right direction/start me off with this please as I am quite clueless on it at present...

I need something that can successfully subtract two dates...


eg. calculate the difference between the current date
02/04/04 (2nd April 04) and 29/03/04 (28th March 04)
...
which will then output a result of 5 days


So what I need to know is...

1.
I need to know how to get the current date from the system clock

2.
I must somehow get my date function converted into European date format (as at present it is in USA format ie. 2nd April 04 is 04/02/04 like April 2nd 04 which is not good!)

3.
and then I must actually SUBTRACT the 2 dates (the current date and a date that is given) from each other to give an integer which I can then use (ie. a value like 5 or 15).


But I have little idea how to go about this


Can anyone please start me off?

DATE Problems - Change Date Format To European, Get Current Date, Subtract 2 Dates?
Need someone to point me in the right direction/start me off with this please as I am quite clueless on it at present...

I need something that can successfully subtract two dates...


eg. calculate the difference between the current date
     02/04/04 (2nd April 04) and 29/03/04 (28th March 04)
     ...
     which will then output a result of 5 days


So what I need to know is...

1.
I need to know how to get the current date from the system clock

2.
I must somehow get my date function converted into European date format (as at present it is in USA format ie. 2nd April 04 is 04/02/04 like April 2nd 04 which is not good!)

3.
and then I must actually SUBTRACT the 2 dates (the current date and a date that is given) from each other to give an integer which I can then use (ie. a value like 5 or 15).


But I have little idea how to go about this


Can anyone please start me off?

Userform Multipage Tab Format
Is it possible to change the font size/colour of the Userform Multipage tabs?

Ta

How To Call Format Cell Userform
Hi guys,

Can anybody tell me how is it possible to call format cell excel built-in userform. Or is it possible to define to see from this userform pages: number, font, border and patterns.

Thanks

Boris

DATE Problem - Formatting US Date MM/DD/YY To European Date Format DD/MM/YY
I have a problem whereby the user must enter a date into a field...

The system changes the date format to US standard which is MM/DD/YY
but I need to change the format to DD/MM/YY (European standard)


I have done this using the Format function, but I still have a slight problem
Format(mydate,"dd/mm/yy")

doesnt account for all dates...

for example...
if I enter 31/03/04 this is fine, it will accept it as that

However, if I enter 02/04/04 (todays date - 2nd April 04), it will change it to 04/02/04



Any ideas how I can counter this from happening?

DATE Problem - Formatting US Date MM/DD/YY To European Date Format DD/MM/YY
I have a problem whereby the user must enter a date into a field...

The system changes the date format to US standard which is MM/DD/YY
but I need to change the format to DD/MM/YY (European standard)


I have done this using the Format function, but I still have a slight problem
Format(mydate,"dd/mm/yy")

doesnt account for all dates...

for example...
if I enter 31/03/04 this is fine, it will accept it as that

However, if I enter 02/04/04 (todays date - 2nd April 04), it will change it to 04/02/04



Any ideas how I can counter this from happening?

Change The Data Format Of A Combobox In A Userform
I am trying to format the date values as returned by a combobox selection. The selection is in "mmmm yyyy" format in Excel, but when a date is selected from the combobox on the userform, the format changes to the number format eg. 39426. I need the user to see the date they have selected. Can anyone help me solve this one please - I am new to VBA and have tried a number of things but cannot find a working solution. Thanks

Elaine

Textbox In A Userform
When trying to use the text entered into a textbox as a filename for example, do i use the event afterupdate() and how do i actually extract the text entered into the textbox

Private Sub TextBox1_AfterUpdate()
Dim filename As String
filename = ?
End Sub

cheers

UserForm && TextBox
I've been a long time lurker and have found some great info from this forum.
Now I have a quick, and hopefully simple, question.

I am creating a userform and want to display some data but I don't want the user to be able to edit it. Is there anyway to display info from a cell besides using a TextBox? Or can you disable the TextBox from updating the cell?

I've searched the forums a few times and found that it can be done using events but just wanted to make sure there wasn't an easier way before I get started.

Thanks in advance!

Textbox In Userform
When trying to use the text entered into a textbox as a filename for example, do i use the event afterupdate() and how do i actually extract the text entered into the textbox

Private Sub TextBox1_AfterUpdate()
Dim filename As String
filename = ?
End Sub

cheers

Add Variable Textbox To Userform
Hello Every body,
I Want To Add Variable Textbox To Userform in excel with INputbox Command

For example:
If User Input 5 in Inputbox then 5 textbox will be created in userform!

Userform Checkbox And Textbox
Hello again,

I have a userform1 with a checkbox1 in it. When I press continue a userform2 comes up. I want when the checkbox1 is checked in userform1 then when userform2 is activated a textbox1 to come up inside userform2.

I have the following.


Code:
If userform1.checkbox1.checked = TRUE then
userform2.???
End if

Can you please help me and tell me how to create a textbox inside userform2 when it is activated?

The basic idea is to have not only one checkboxes in userform1 but around 20. Each time userform2 is activated a checkboxes should appear as many checkboxes checked.

Thank you for you help in advance

Date Control Userform Formatting
Hi,

I am having trouble getting the date to format in a textbox on a user form. The date ideally will be formatted as dd/mmm/yyyy with dots sepearting instead of the /'s.

I have tried the following as code to adjust the formatting and it doesn't recognise any including .numberformat

Me.txtdate.Value = Format(txtdate.Text, "dd/mmm/yyyy")

Me.txtdate.NumberFormat(txtdate.Text, "dd/mmm/yyyy")
but numberformat doesnt spring up as an option

txtdate.NumberFormat = "dd/mmm/yyyy"

I always get the number not date format. Eg.

2-may-2005 will show as 38474

I also need it to insert to the textbox that the cursor was last focused in. Instead I seem to have one textbox tied to the control.

I am using code like this to print the value selected on the control

txtdate.Value = CDbl(Calendar1.Value)

How would I change it to add the date to the last textbox with focus?

Thanks
Rob

Format Currency To Indian Format In Label/Textbox
Hi folks,
I am trying format the currency data in DB (Acs 2003) into Indian currency format 00,00,00,000 for which I used the below code

vbcode Code:
Me.lblAmt.Caption = Format(CCur(rsCurrent.Fields("suitAmount")), "##,##,##,##,##,##0")

but during display nothing happens i.e. the display continues to be the US format.
Can somebody show me how.
Thanks in advance.

Validating Input From Textbox On Userform
I have created a userform which has three textboxes on it.

I want to validate the input from this form when the user clicks a submit button.

If the data is invalid I want to return focus to the textbox which has the error.

I thought (in my naivety) that I could simply use setfocus (on the appropriate textbox) and the cursor would be positioned there for the user to correct the error.

This doesn't work! Anyone out there point me in the right direction please?

Validate Textbox Entry In Userform
I want to check to see if a textbox entry is valid and prompt the user immediately with a message box if they make an invalid entry. I am trying to use the "Exit" Event procedure but I'm having difficultly getting it to work. I don't really understand what (ByVal Cancel As MSforms.Returnboolean) means.

Any help?

UserForm TextBox Formatting Question
I am trying to format a textbox in one of my userforms through VBA in Excel. The control source for the textbox is a cell in an Excel spreadsheet. I have the spreadsheet cell formatted as currency with two decimal places in the spreadsheet. So, the cell shows $2,000.00, but when I view the data in my userform the text box in the userform only shows 2000.

1. How can I format the textbox in the userform to show its value in currency format?

2. How can I format the textbox in the userform to only go two decimal places out?

Please help...

Thanks!!!!

Chris

Formatting TextBox In UserForm For Dates
I have created a VBA UserForm for Word2003 so I can automate the creation of legal documents. In several fields, the user must type in a date. Is there a way to ensure that the user has typed in a correct date?

Once I confirm that the entry is a date, I need to do several things:
- Add a specific amount of time (say, 3 years) to the entered date

- Add that calculated future date to the default of another field on the userform

- Enter that date in the long form (eg., November 20, 1966 rather than 11/20/66) into a Word document.

I'll be grateful for any help you can provide. Thanks!

Karol Brown

Excel Userform Date Time Problem
hi all,
I have made up a userform made up of textboxes and combo boxes, quite an achievment for a self taught begineer like me. one of the text boxes has this code

Private Sub UserForm_Activate()
TextBox3.Value = Now()
End Sub

the format keeps changing by its self, one day i get 1/12/05, the next it can be
13/1/05, I understand the american/ uk time formats are different, is there a code that will sort this out for me


any advice for a begineer


thanks

Setting Long - Short Date Format In Date Time Settings
How can i set the Date Time Setting Format in Control Panel

i m usiing window Xp


also i want the date format in dd/MM/yyyy

UserForm Textbox, Make Input Be UPPERCASE Only?
If there's a will, there's a way, right?

Can a UserForm text box be made to only accept entries that are made with the Upper Case only?

if input is in lower case, then I'd need an error message box stating that the capslock is turned off, please turn on and make entry.

Thanks for everyone's attention to this question =)

Date Conversion As Oracle Database Date Default Format
Select sysdate from dual ; //oracle database
The result is : 28-AUG-04

How to convert “date” in vb to the above format?

Using below statement :
FormatDateTime(Date, vbLongDate) // Saturday, August 28, 2004

Then, combine with string functions (such as instr, left, mid, etc) can be achieved the desired result.

Any shortcut than above mentioned?

Thanks.
vb999

Date Format, Count No. Of Days & Highlight Date In Calendar
<html><div style='background-color:'><DIV>
<P>Hi all,</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">Happen to visit this website accidentally and found that it’s very useful to VB beginner like me. <SPAN style="mso-spacerun: yes"> </SPAN>I have the following problems and would appreciate your kind assistance to enlighten me.<SPAN style="mso-spacerun: yes">  </SPAN>Attached is my file for your checking.<SPAN style="mso-spacerun: yes">  </SPAN></P></DIV>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"> <?XML:NAMESPACE PREFIX = O /><O:P></O:P></P>
<DIV></DIV>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; tab-stops: list .5in; mso-list: l0 level1 lfo3">1)<SPAN style="FONT: 7pt 'Times New Roman'">      </SPAN>Sometimes, the number of days is incorrect with a big figure (e.g from 1 to 30 Apr) or even a negative figure after I change the system’s date format from “mm/dd/yyyy” to “dd/mm/yyyy”.<SPAN style="mso-spacerun: yes">  </SPAN></P>
<DIV></DIV>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.25in"> <O:P></O:P></P>
<DIV></DIV>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; tab-stops: list .5in; mso-list: l0 level1 lfo3">2)<SPAN style="FONT: 7pt 'Times New Roman'">      </SPAN>In calculating the number of days, I need to exclude Sunday.<SPAN style="mso-spacerun: yes">  </SPAN>By using the “WeekDay (Calendar1) = 7 “ method, I still didn’t get the correct result.<SPAN style="mso-spacerun: yes">  </SPAN></P>
<DIV></DIV>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"> </P>
<DIV></DIV>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><O:P>      3)  How to highlight a certain date in calendar with different colour to indicate it's a public holiday ? </O:P></P>
<DIV></DIV>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><O:P></O:P> </P>
<DIV></DIV>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">Many thanks in advance.<SPAN style="mso-spacerun: yes">  </SPAN></P>
<DIV></DIV>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"> <O:P></O:P></P>
<DIV></DIV>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">Best regards,</P>
<DIV></DIV>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">YC </P>
<DIV></DIV>
<DIV></DIV>
<P><BR><BR></P>
<DIV></DIV>
<DIV></DIV></div><br clear=all><hr>Add photos to your e-mail with <a href="http://g.msn.com/8HMVEN/2746">MSN 8.</a> Get 2 months FREE*.</html>

Date && Time Values In Date And String Format Differ
The program (debug) output below lists the last modification time of two files. File 1 is stored on a NTFS medium, file 2 sits on a FAT medium.

In order to be able to compare these dates, I need to round the odd seconds of the NTFS file up (FAT files have only even second values).

The lines after the file headers show the date & time value before and after the rounding, in date, double precision and string format.

file 1 (NTFS)
= 2005-07-12 08:57:09 = 38545,3730208333 = 2005-07-12 08:57:09
after rounding up
= 2005-07-12 08:57:10 = 38545,3730324074 = 2005-07-12 08:57:10

file 2 (FAT)
= 2005-07-12 08:57:10 = 38545,3730324074 = 2005-07-12 08:57:10

The strange thing is that when comparing these values, they appear to be different (!) both in date and double data format, not in string format.

2005-07-12 08:57:10 > 2005-07-12 08:57:10 (date format)
38545,3730324074 > 38545,3730324074 (double precision format)
2005-07-12 08:57:10 = 2005-07-12 08:57:10 (string format)

Any idea where this difference comes from?

Rounding up was done with DateAdd.

VB version 6, on XP.
Boiled down code has been attached.

Draw Textbox, Format Border And Type Text Into Textbox In A .doc File
I use this codes to open a .doc file and draw a textbox in it. What should I add to input text into the textbox (I used Selection.Text = "......." but the text are outside the textbox) and format it's borders?
[font=courier new][color=darkblue]
Private Sub Command1_Click()
Dim objWord As New Word.Application
Dim objDoc As Word.Document

objWord.DisplayAlerts = wdAlertsNone
Set objDoc = objWord.Documents.Add

objDoc.Shapes.AddTextbox msoTextOrientationHorizontal, 100, 100, 100, 300

objDoc.SaveAs "C:WINDOWSDesktoplabel.doc", wdFormatDocument
objWord.Quit

cmdEnd.SetFocus

Making Sure The User Enters A Date In Date Format
How do I ensure a user enters text in a textbox in date format? i.e. when the user enters into the textbox it automatically has:
--/--/--
and only allows the user to entera valid date.

How To Set The Date Into Long Date Format In The Regional Settings?
how can i SET the date into long date format (regional settings)?

i want that once my form is loaded, it will automatically SET the date in the regional settings into long date format.

How To Setfocus A Textbox In Userform With Properties MDIChild=true
Hi every body
How to setfocus a textbox in userform with properties MDIChild=true?
Can you help me , please
Thanks a lot

Sharing Variables Captured From A Textbox On A Userform With Other Modules
My apologies in advance for the possible simplicity of this one , predominantly I use VB to enhance Excel I am trying to move away from input boxes as a means of data capture from the user, therefore I want to use my own forms, I am having no luck sharing data from a textbox entry with other elements of my program can anyone explain how this is done is laymans terms ?

As well as an explanation if someone has any example code I would be extremely grateful !

Regards and thanks

Paul Anas

VBA: Read Textbox Fields (userproperties) From Outlook Userform Sent As Attachment
I have customized outlook messages with textboxes bound to fields. Most of them are sent directly, but some go through several different people and end up attached to other messages. I can't figure out how to access the fields (i.e. userproperties) when the message is sent to me as an attachment. I am using VBA to pull the information from the textbox fields into an Excel spreadsheet.

Here is my code, including various blocks using different approaches (all commented out):


Code:
Sub import_test()

Dim olApp As Outlook.Application 'Outlook Application
Dim olNameSpace As Outlook.NameSpace 'Outlook NameSpace
Dim olFromFolder As Outlook.MAPIFolder 'Outlook MAPIFolder
Dim olToFolder As Outlook.MAPIFolder 'Outlook MAPIFolder
Dim olMailItem As Outlook.MailItem 'Outlook Mail Item
Dim olMailItem2 As Outlook.MailItem 'Outlook Mail Item
Dim olAttachment As Outlook.Attachment 'Outlook Mail Item Attachment

Dim objOutlk
Dim objMail As Object

' named counters
Dim NextRow As Integer
Dim NumberOfItemsToProcess As Integer
Dim intItemCountMax As Integer

' unnamed counters
Dim R As Integer
Dim I As Integer
Dim J As Integer
Dim K As Integer
Dim L As Integer

On Error Resume Next

Set olApp = CreateObject("Outlook.Application")
Set olNameSpace = olApp.GetNamespace("MAPI")

'choose your working folders
Set olFromFolder = olNameSpace.PickFolder 'opens a folder selection tree
Set olToFolder = olNameSpace.PickFolder 'opens a folder selection tree

Sheets("Sheet3").Activate 'set the worksheet to be used
NextRow = Application.WorksheetFunction.CountA(Range("A:A")) + 1 'find the first blank row in column A
Cells(NextRow, 1).Select 'set the active cell

NumberOfItemsToProcess = InputBox("Number of messages to process?") ' ask user how many mail items to process in this run
If NumberOfItemsToProcess > olFromFolder.Items.Count Then NumberOfItemsToProcess = olFromFolder.Items.Count ' validate # of mail items to be processed

'Application.ScreenUpdating = False 'makes code run faster

For I = NumberOfItemsToProcess To 1 Step -1 'set the counter loop to the number of items to be processed

Set olMailItem = olFromFolder.Items(I) 'select the next mail item

[b]'this is the problem area: what I actually want to do is access an attachment and loop through its user properties like I do with the olMailItem later[/b]


[b]'I have tried:[/b]
' With olMailItem.Attachments
' R = .Count
' If R > 0 Then
' For K = 1 To R
' MsgBox (.Item(K) ' Note: "userproperties" is not available here. ".DisplayName", ".Remove", etc. all work fine.
' Next K
' End If
' End With

[b]'I also tried:[/b] ( Watching "olMailItem2" while I step through the following code shows that "olMailItem2" always has a value of "nothing" )
' R = olMailItem.Attachments.Count
' While R > 0
' 'If olMailItem.Attachments.Item(R) = "MailItem" Then
' Set olMailItem2 = olMailItem.Attachments.Item(R)
' MsgBox olMailItem2.UserProperties.Item("Product Name").Value
' 'End If
' R = R - 1
' Wend
'

[b]'These code blocks work if "olMailItem" is a mail message in an outlook folder, but not if I try to set an attachment as "olMailItem"[/b]

' For J = 1 To olMailItem.UserProperties.Count 'count the userproperties and set the counter loop
' Cells(ActiveCell.Row, J) = olMailItem.UserProperties.Item(J).Name 'import the name of the userproperty
' Cells(ActiveCell.Row + 1, J) = olMailItem.UserProperties.Item(J).Value 'import the value of the userproperty
' Next J 'select next userproperty in the mailitem
' ActiveCell.Offset(2, 0).Select 'move to the next blank row (skipping one because each loop writes data to two rows)


'For L = 1 To 4
' If olMailItem.UserProperties.Item("Date Needed " & L).Value <> "" Then
' ActiveCell.Offset(L - 1, 0).Value = Format(olMailItem.ReceivedTime, "mm/dd/yy")
' ActiveCell.Offset(L - 1, 1).Value = olMailItem.UserProperties.Item("Product Name").Value
' ActiveCell.Offset(L - 1, 5).Value = olMailItem.UserProperties.Item("Date Needed " & L).Value
'
'(I pull several additional values here before looping)
'
' K = K + 1
' End If
'Next L
'ActiveCell.Offset(K, 0).Select
'K = 0

'olMailItem.UnRead = False 'mark mailtem as read
'olMailItem.Move olToFolder 'move mailitem

Next I

'Application.ScreenUpdating = True

' Clean up
Set olMailItem = Nothing
Set olMailItem2 = Nothing
Set olNameSpace = Nothing
Set olApp = Nothing
Set olFromFolder = Nothing
Set olToFolder = Nothing

MsgBox ("finished")

End Sub

Any hints on how to handle this would be very much appreciated.

Getting Numbers In Date Field Into Date Format???
in my access db i have an old table and the dates were never formatted eg its just 791023 as in 23 of oct 1979 so i had to change that to get it in date format so i did this using a query

UPDATE history_date SET history_date.theDate = format([theDate]," mm/dd/yy");

like it worked and put in the slashes but the date is different
it came out 01/25/55 when the date was originally 641027
why is it changing it ???
like i tried diff format like yy/mm/dd and still the same...
confused!!please help if u know anything...

Format String To Date Format And ....
Question one,
If a user types 4/5/03 into a textbox, how do I format this to this date style - 04/05/03?

They may type it as I want, or they may type it like the above, so I need to make sure before I do part two, below, that it is in the correct format.

Part two,
How can I compare the month part of the date (05) with a Month name (e.g. September) in a Flexgrid. I know I can use the textmatrix to get the name of the month. Would the best way be to use a select case to compare the months?

Format String To Date Format And .....
Question one,
If a user types 4/5/03 into a textbox, how do I format this to this date style - 04/05/03?

They may type it as I want, or they may type it like the above, so I need to make sure before I do part two, below, that it is in the correct format.

Part two,
How can I compare the month part of the date (05) with a Month name (e.g. September) in a Flexgrid. I know I can use the textmatrix to get the name of the month. Would the best way be to use a select case to compare the months?





Edited by - andy99 on 9/25/2003 9:57:39 AM

Valid Date/Date Format
You guys were probably doing this one in third grade...

I have a textbox on a form in which a user enters a date. I want the user to always enter the date in the following format: mm/dd/yy

When they click OK, how can I check to make sure it's a valid date and it's in the format I want, no other format?

Thanks!!

Empty Date && Date Format
I have in my table a field where I have now a date like
#01-Jan-2004#
But, for a specific reason, I want to delete that date and leave the field empty.
How can I do that? Is there any constant for the "empty date"?
If I try #00-00-00# I get an error.

And another question:
Is there any chance to set the date format? I don't want to depend on computer settings!!! I want to be sure that if the user will write in a text box
"02-03-2004"
this will be "02-Mar-2004" and not "Feb-03-2004"

Date Format But Not Current Date HOW?
I am new to VB. Work with VB5 Enterprise.

I think this should be simple, but I cannot figure it out:

How do I create a text-box in which the user can write a random date that is not today's date. And still keep the date format?

Example: User inputs 12122009 and I want textbox to change into: 12-12-2009 or 12:12:09 or 12-12-09 or 12:12:2009.

The change should be instant or at the latest at "lost focus".

All the examples I have found work with the current date.

Any ideas?

All the best
Svanholm



How To Get The Right Date Format After Adding A Date
Hi ,

The below is the Code in the Timer. The Purpose is to when the Time Reaches the process should done. The process is

Reading a Encrypted text from the file named ImpDate.TXT, the Text is the date and its Format Is (“MM/DD/YYYY HH:MM:SS AM/PM”).

After reading it I am storing it in a string. Then I need to add one day with Date which I get and Decrypted. Then again I will encrypt it and over write the ImpDate.TXT File.

Private Sub Timer1_Timer()

MyTime = Format(TimeValue("12:05:50 PM"), "HH:MM:SS AM/PM")
CurTime = Format(Time, "HH:MM:SS AM/PM")

If MyTime = CurTime Then

‘’ Reading the Encrypted Text from the File
    Open "C:chsImpDate.TXT" For Input As #1
    While Not EOF(1)
    Line Input #1, st
    Wend
    Close #1
   
 Secret$ = st
  Password$ = "vehiclesystem"
‘’Decrypting the Encrypted Text and add one day with it and again I have Encrypt and Store. For testing whether the one day is added or not, I write it in a file DecDate and checked.

  Call Decrypt(Secret$, Password$)
   sts = Format(st, "MM/DD/YYYY")
       Dim nFile As Integer
    nFile = FreeFile
    Open "C:chsDecDate.TXT" For Append Shared As #nFile

    Print #nFile, sts
    Close #nFile
End If
End Sub

The problem is I am getting the wrong date is coming as below

01/27/1900 12:00:00 AM

tried in various ways but not coming the correctly.

Thank you very much,
Chock.

How To Validate A Date When Date Format Is Different
How validation of date whould be done where date format is "dd/MM/yyyy" and windows date format is "MM/dd/yyyy"

Copyright © 2005-08 www.BigResource.com, All rights reserved