Copy 1 Text Field into another on Form, DateAdd and macros

M

Michael Anderson

1. How do I copy 1 text Field's value into another text Field from a cmd
button? I am trying to customise the Outlook Contact Form. I notice that
there is no code underneath it and so I can't debug it with MS Script Editor.
2. Why doesn't the code below work? I've used DateAdd to add 12 months on to
a date...
-- below is code -- (mxz...is a user-defined prefix)

Sub Item_CustomPropertyChange(ByVal Name)
If Name = "mxzMembershipStartDat" Then
Dim dteNextDate As Date
Dim dteDate As Date

dteDate = dtemxzMembershipStartDat
dteNextDate = DateAdd("m", 12, dteDate)
dtemxzMembershipRenewalMonth = dteNextDate
End If
End Sub


3. How can i get 2 macros to load automatically with a form?
 
T

Tangent

Well, it's really the same soultion: You have to pull the objects from the
Item.UserProperties() collection to do things with them. This is also why
your function does not work. Something like this works:

Sub Item_CustomPropertyChange(ByVal Name)
If Name = "dateField1" Then
dteDate = Item.UserProperties("dateField1").Value
dteNextDate = DateAdd("m", 12, dteDate)
Item.UserProperties("dateField2").Value = dteNextDate
End If
End Sub

Update other textboxes the same way. If you are entering data in to builtin
fields, just make sure you access them through the right collection.

Regarding loading two macros with a form, I'm not sure what you're asking.
Do you want to embed the macros in the form? Or do you want to launch macros
that exist in your VBAProject.OTM (these are the macros that you see in the
Tools > Macros... list, they are specific to each PC's VBAProject.OTM file
unless you have a deployment soultion in place).

Thanks,
Tangent
 
M

Michael Anderson

THanks for your help.

RE 3rd question - I want to embed these macros on a form. When the form
loads, these macros would be embedded in it. 1 of these cmd_click()macros
performs the actions of the 1st question. The other cmd_click()macro updates
another date field (see 2nd question). I was asking this in case the direct
programming on the forms didn't work. (Like 2nd Question - ie Sub
Item_CustomPropertyChange(...))
 
M

msnews.microsoft.com

Ah. Well, in the event that you still wanted to handle clicks, you would
embed the macros the same way you created the custompropertychange event
handler. only it would be a click handler. Then you'd just check what they
clicked on, and then execute the proper code - or do nothing.

I personally like to leave buttons out of it if possible. Your use of the
CustomPropertyChange event is preferrable.

Thanks,
Tangent
 
M

Michael Anderson

Here is some more RE questions 1 and 2.

Below is the only code on a customised Outlook Form. Nothing happens. Can
anyone please tell me why?

Sub Item_CustomPropertyChange(ByVal Name)

Dim dteNextDate as Date
Dim dteDate as Date
Dim objApp as Application
Dim objNS as NameSpace

Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")

If Name = "mxzMembershipStartDate" Then
dteDate = Item.UserProperties("mxzMembershipStartDate").Value
dteNextDate = DateAdd("m", 12, dteDate)
Item.UserProperties("mxzMembershipRenewalMonth").Value = dteNextDate
End If

Set objApp = Nothing
Set objNS = Nothing

End Sub

Sub cmdmxzAddressButton_Click()

Dim objApp as Application
Dim objNS as NameSpace

Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")

Item.UserProperties("mxzBusinessSuburb").Value =
Item.UserProperties("mxzOtherSuburb").Value

Set objApp = Nothing
Set objNS = Nothing

End Sub


I also get the Error Message 3 before the Form loads saying "Expected End of
Statement Line 3".
 
M

msnews.microsoft.com

Michael:

Comment out all of the lines having to do with objApp and objNS, and comment
out all of the Dim statements. Then run your form again.

The reason it doesn't do anything is because Expected EOL error dumps the
entire script. Thus, no scripts run on that page. The EOL error is coming
from your Dim objApp as Application.

In this particular case, don't worry about Dims and I'm not really sure why
you're grabbing objApp or objNS, just to connect/logon? I don't think you
need to worry about it unless you plan to do something with our friend
MAPI... like send mail.

Thanks,
Tangent
 
M

Michael Anderson

Thank You for your help.

I've done what you have said, but nothing happens.
 
M

Michael Anderson

Sorry, anyone got any suggestions as to why I get the Error Message # 3
before the Form loads saying "Expected End of Statement Line 3".

--
Thank You in Advance,

Michael Anderson


Michael Anderson said:
Thank You for your help.

I've done what you have said, but nothing happens.
 
K

Ken Slovak - [MVP - Outlook]

Is that with form code? Form code is VBScript, where everything is a Variant
and As clauses are not allowed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top