Form Coding Help

C

Curtis Stevens

Got two forms & different tables. Customers & Affiliates

I'm trying to create an onclick event where when I'm in the Customers form,
I check this box saying this customer has been referred by this particular
affiliate (which there is another box with affiliate's ID & what is linking
that customer to that particular affiliate). When they do that, this code is
initiated to create an html email. My problem is the coding I have below,
the errors is "Me.ContactName" and "Me.Email", because it is suppose to grab
that information from the affiliate table/form for that particular affiliate
that referred that customer. But I'm not in the Affiliate's form & it isn't
open, which if I put that code somewhere on that form, it works just fine....
Any help?

Const olMailItem = 0
txtDir = "C:\USMS\Emails\"

Set objoapp = CreateObject("Outlook.Application")
Set objOMessage = objoapp.CreateItem(olMailItem)
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso_OpenTextFile(txtDir & "AffiliateReferral", 1)

txtbody = ts.ReadAll
txtbody = FindAndReplace(txtbody, "ContactName", Me.ContactName)

With objOMessage
.to = Me.Email
.Subject = "You Made a Referral!"
.htmlbody = txtbody
.Display
End With
 
M

Mr. B

Got two forms & different tables. Customers & Affiliates

I'm trying to create an onclick event where when I'm in the Customers form,
I check this box saying this customer has been referred by this particular
affiliate (which there is another box with affiliate's ID & what is linking
that customer to that particular affiliate). When they do that, this code is
initiated to create an html email. My problem is the coding I have below,
the errors is "Me.ContactName" and "Me.Email", because it is suppose to grab
that information from the affiliate table/form for that particular affiliate
that referred that customer. But I'm not in the Affiliate's form & it isn't
open, which if I put that code somewhere on that form, it works just fine....
Any help?

Const olMailItem = 0
txtDir = "C:\USMS\Emails\"

Set objoapp = CreateObject("Outlook.Application")
Set objOMessage = objoapp.CreateItem(olMailItem)
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso_OpenTextFile(txtDir & "AffiliateReferral", 1)

txtbody = ts.ReadAll
txtbody = FindAndReplace(txtbody, "ContactName", Me.ContactName)

With objOMessage
.to = Me.Email
.Subject = "You Made a Referral!"
.htmlbody = txtbody
.Display
End With

Sounds like your Affilliate's from may be a sub form or you have both
forms open at the same time. In either case, you would need to fully
qualify your call to the control on the Affilliates form.

If the Affilliates form is a sub form then you would use:
Forms![NameOfMainForm]![NameOfSubForm].Form![NameOfControl]

If the Affilliates form is just another form that is open, you would
use:
Forms![NameOfForm]![NameOfControl]

HTH

Mr. B
 
C

Curtis Stevens

Maybe this is too complicated, but let see if I can clarify this. When I'm
on customers form, I check a box that says affiliate referred and in another
field, type in the affiliates ID. This form called customers is tied to a
table called customers, which has a relationship with a table called
affiliates via that field. Affiliates table has a form called Affiliates.
Now, this code below is wanting to grab the information for the applicable
affiliate that has been referenced on the Customers form, which has this
coding. In other words, you are on customers form, you give this particular
customer record an affiliate ID and when you click the button, the code grabs
the relevant information such as name from the affiliate table/form that is
the one that has been selected as the referrer in the customer form.

Sorry for just now replying, the forums have been down for me since 6/5.

Thanks
Curtis


Got two forms & different tables. Customers & Affiliates

I'm trying to create an onclick event where when I'm in the Customers form,
I check this box saying this customer has been referred by this particular
affiliate (which there is another box with affiliate's ID & what is linking
that customer to that particular affiliate). When they do that, this code is
initiated to create an html email. My problem is the coding I have below,
the errors is "Me.ContactName" and "Me.Email", because it is suppose to grab
that information from the affiliate table/form for that particular affiliate
that referred that customer. But I'm not in the Affiliate's form & it isn't
open, which if I put that code somewhere on that form, it works just fine....
Any help?

Const olMailItem = 0
txtDir = "C:\USMS\Emails\"

Set objoapp = CreateObject("Outlook.Application")
Set objOMessage = objoapp.CreateItem(olMailItem)
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso_OpenTextFile(txtDir & "AffiliateReferral", 1)

txtbody = ts.ReadAll
txtbody = FindAndReplace(txtbody, "ContactName", Me.ContactName)

With objOMessage
.to = Me.Email
.Subject = "You Made a Referral!"
.htmlbody = txtbody
.Display
End With

Sounds like your Affilliate's from may be a sub form or you have both
forms open at the same time. In either case, you would need to fully
qualify your call to the control on the Affilliates form.

If the Affilliates form is a sub form then you would use:
Forms![NameOfMainForm]![NameOfSubForm].Form![NameOfControl]

If the Affilliates form is just another form that is open, you would
use:
Forms![NameOfForm]![NameOfControl]

HTH

Mr. B
 

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