Possible - Onclick Event - Insert Text into a Field in Another Tab

G

Guest

Is this possible? I have a form where I want a button with an onclick event
to paste some text into a field of a whole other table, that has a
relationship to the main table. In other words, I have a main form, with all
my customer info and a sub form in it, called the call log, where I log
everything, what I say to them, etc. That sub form points to another table,
that has a relationship to the main table, for that record, so each customer,
has its own record in that table.

Main Table: Customers
Main Form: Current
Sub Table: Followup Notes
Sub Form: Followup Notes Subform

I want to place a button on my main form, Current.

Anyone can help with the code or point me to a site that helps with this?

Thanks
Curtis
 
S

strive4peace

Hi Curtis,

firstly, do not use "Current" for your form name -- that is a reserved
word. Change it to something like CurrentCustomer

Also, it is a good idea to avoid using spaces in names

Followup Notes --> FollowupNotes

when you say you want to paste text into another table... I must ask
why? If you have a link to the record in Customers with the text, you
do not need to store it somewhere else as well unless you need to be
able to change it.

What is the other tablename? Do you need to add or update a record? If
update, what is the field to link the 2 tables.

Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*
 
G

Guest

Hi Crystal,

Thanks for the response, greatly appreciate it!

1. Been using Current for the longest time & never an issue... If I change
the table name, wont I have to go into all the VB coding of every form &
change it too?

2. If a customer is approved, but there is a stipulation, I have a button I
click and it creates that file - a report, prints it into a PDF file and then
attaches it to an email ready to send. I want to then update my call log for
that customer saying emailed stip document, etc. So I don't have to manually
type it out.

The other table name is mentioned above, Followup Notes

Does this make sense?

Thanks
Curtis
 
S

strive4peace

Hi Curtis,

you haven't had an issue YET...

1. generally, you should not have a LOT of forms where Current is
used... it is better to change it now before you build anymore. Don't
forget to change combobox and listbox RowSource too where used.

Reserved words
http://www.allenbrowne.com/AppIssueBadWord.html

2. you can use an UPDATE query

~~~~~~~~~~~ UPDATE ~~~~~~~~~~~
An Update Query first identifies the tables that are used

UPDATE table1 INNER JOIN table2 ON table1.keyfield =
table2.keyfield

Then identifies what to change

SET table1.fieldtochange = expression

Then, if you have criteria...

WHERE table.strField = 'somevalue'
AND table.numField = 99
AND table.dateField = #1/1/06#

'~~~~~~~~~~~~~~~~

to run SQL in code:

'~~~~~~~~~~~~~~~~
dim strSQL as string

strSQL = "UPDATE Tablename " _
& " SET fieldname = 'strValue' " _
& " WHERE conditions;"

currentdb.execute strSQL, dbFailOnError
currentdb.tabledefs.refresh
'~~~~~~~~~~~~~~~~

Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*
 
G

Guest

Sorry, I have gone over what you are saying a hundred times, don't understand
what I"m suppose to do exactly. I know VB pretty good, enough to get around,
but I'm no expert....
 
S

strive4peace

Hi Curtis,

in order to better help, you need to answer the questions that are asked...

in your first post, you say, "I want to place a button on my main form,
Current"

.... but you do not say what you want the button to do

so I asked:

when you say you want to paste text into another table... I must ask
why? If you have a link to the record in Customers with the text, you
do not need to store it somewhere else as well unless you need to be
able to change it.

What is the other tablename? Do you need to add or update a record? If
update, what is the field to link the 2 tables.

then, you said:
"I want to then update my call log for that customer saying emailed stip
document, etc. So I don't have to manually type it out."

because you did not supply tablenames and fieldnames, I gave you a
generic example. The example can be made to suit your needs if you
provide more information ;)



Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*
 
G

Guest

Ok, how about this?

I have this check box, when I click on it, it does something, which I pasted
the code below. I then want it to do this after it performs this first task,
the code I have below. This second task is to insert some text into the
"Subject" field on the next line in my call log section. Refer to my screen
shot here: http://www.gotmerchant.com/dbdesign.jpg In that screen shot, it
is the bottom section, has date, time, description & a check box. Now when I
check this check box, have it do the task I have below and then insert some
specified text into this call log section I'm describing. The date & time is
auto done, I just want some info pasted in the next available line, in the
subject field, like emailed stip requirement document, etc. This call log
section I'm referring to is a subform called Followup Notes Subform. Its
table name is called Followup Notes. Followup Notes is tied to the main db
table, using the contact ID field. The name of the field in the call log
subform I want updated is called Subject. The name of the form this call log
form is on, the main form you see in the screen shot is called Current, which
is a subform in the tab control box with that form having a name of Customer
Management Screen, but I usually figure that out by doing something like
[Customer Management Screen]![Current], etc....

Does this provide you with everything?



ON CLICK EVENT CODE FOR CHECK BOX:

Private Sub Ctl100__Reserve_Click()
On Error GoTo handler

Dim objOMessage As Object
Dim txtbody As String

Const olMailItem = 0

Set objOApp = CreateObject("Outlook.Application") 'created the
application here
Set objOMessage = objOApp.CreateItem(olMailItem) ' and last here is
an Mail Item

txtbody = "Dear " & Me.Merchant_Principal1 & "," & vbCrLf & vbCrLf & _
"Our industry receives a lot of applications using stolen
identities." & vbCrLf & _
"To help avoid losses, some new accounts are placed on a" & vbCrLf & _
"temporary hold until the merchant's first transaction can be" &
vbCrLf & _
"verified. In other words, the risk department simply wants to" &
vbCrLf & _
"hold the funds until they are able to verify your very first
transaction." & vbCrLf & _
"This is a one-time event and will be removed upon transaction" &
vbCrLf & _
"verification." & vbCrLf & vbCrLf & _
"Please feel free to email or fax us your first transaction's" &
vbCrLf & _
"invoice so we can ensure the risk department removes the hold." &
vbCrLf & _
"The fax number is 281-500-4600." & vbCrLf & vbCrLf & _
"Thank you for your business and understanding." & vbCrLf & vbCrLf & _
"Have a Great Day!" & vbCrLf & vbCrLf & _
"=======================================" & vbCrLf & _
"Curtis Stevens - Personal Account Manager" & vbCrLf & _
"Gotmerchant.com" & vbCrLf & vbCrLf & _
"""Service with a Personal Touch!""" & vbCrLf & vbCrLf & _
"Online: http://www.gotmerchant.com" & vbCrLf & _
"Phone: (936) 293 - 8567 or (800) 60 KEYPAD" & vbCrLf & _
"=======================================" & vbCrLf & vbCrLf & _
""

With objOMessage
.To = [Forms]![Customer Management Screen]![Potential]![Biz Email
Address]
.Subject = "Approval Stipulation"
.body = txtbody
.Display
End With

handler:
If Err.Number = -2147024894 Then
End If
 
S

strive4peace

Hi Curtis,

your questions are answered in-line...


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*



Curtis said:
Ok, how about this?

I have this check box, when I click on it, it does something, which I pasted
the code below. I then want it to do this after it performs this first task,
the code I have below.

you can call this procedure from another on the same module sheet by
entering this statement:

Ctl100__Reserve_Click


This second task is to insert some text into the
"Subject" field on the next line in my call log section. Refer to my screen
shot here: http://www.gotmerchant.com/dbdesign.jpg In that screen shot, it
is the bottom section, has date, time, description & a check box.

please provide more details such as the subform name, the control name,
and its relative path from where you are

Now when I
check this check box, have it do the task I have below and then insert some
specified text into this call log section I'm describing. The date & time is
auto done, I just want some info pasted in the next available line, in the
subject field, like emailed stip requirement document, etc.

so are you wanting to create a new record? If so, it would be best to
use an APPEND query to add a record and fill the information -- please
provide the the fieldnames to fill out in your [Followup Notes] table,
their data types, the linking field name(s), and the control name for
the linking field.

After the record is added, you will need to requery the subform --
please provide the relative path from where you are for the subform --
is it a subform directly? Or is it a subform of a subform?


This call log
section I'm referring to is a subform called Followup Notes Subform. Its
table name is called Followup Notes. Followup Notes is tied to the main db
table, using the contact ID field. The name of the field in the call log
subform I want updated is called Subject. The name of the form this call log
form is on, the main form you see in the screen shot is called Current, which
is a subform in the tab control box with that form having a name of Customer
Management Screen, but I usually figure that out by doing something like
[Customer Management Screen]![Current], etc....

Does this provide you with everything?



ON CLICK EVENT CODE FOR CHECK BOX:

Private Sub Ctl100__Reserve_Click()
On Error GoTo handler

Dim objOMessage As Object
Dim txtbody As String

Const olMailItem = 0

Set objOApp = CreateObject("Outlook.Application") 'created the
application here
Set objOMessage = objOApp.CreateItem(olMailItem) ' and last here is
an Mail Item

txtbody = "Dear " & Me.Merchant_Principal1 & "," & vbCrLf & vbCrLf & _
"Our industry receives a lot of applications using stolen
identities." & vbCrLf & _
"To help avoid losses, some new accounts are placed on a" & vbCrLf & _
"temporary hold until the merchant's first transaction can be" &
vbCrLf & _
"verified. In other words, the risk department simply wants to" &
vbCrLf & _
"hold the funds until they are able to verify your very first
transaction." & vbCrLf & _
"This is a one-time event and will be removed upon transaction" &
vbCrLf & _
"verification." & vbCrLf & vbCrLf & _
"Please feel free to email or fax us your first transaction's" &
vbCrLf & _
"invoice so we can ensure the risk department removes the hold." &
vbCrLf & _
"The fax number is 281-500-4600." & vbCrLf & vbCrLf & _
"Thank you for your business and understanding." & vbCrLf & vbCrLf & _
"Have a Great Day!" & vbCrLf & vbCrLf & _
"=======================================" & vbCrLf & _
"Curtis Stevens - Personal Account Manager" & vbCrLf & _
"Gotmerchant.com" & vbCrLf & vbCrLf & _
"""Service with a Personal Touch!""" & vbCrLf & vbCrLf & _
"Online: http://www.gotmerchant.com" & vbCrLf & _
"Phone: (936) 293 - 8567 or (800) 60 KEYPAD" & vbCrLf & _
"=======================================" & vbCrLf & vbCrLf & _
""

With objOMessage
.To = [Forms]![Customer Management Screen]![Potential]![Biz Email
Address]
.Subject = "Approval Stipulation"
.body = txtbody
.Display
End With

handler:
If Err.Number = -2147024894 Then
End If
 
G

Guest

so are you wanting to create a new record? If so, it would be best to
use an APPEND query to add a record and fill the information -- please
provide the the fieldnames to fill out in your [Followup Notes] table,
their data types, the linking field name(s), and the control name for
the linking field.

After the record is added, you will need to requery the subform --
please provide the relative path from where you are for the subform --
is it a subform directly? Or is it a subform of a subform?

Form POTENTIAL has the button to click that performs the Action. It is a
subform of the main form - Customer Management Screen

Sub Form Name (has the table where I want the record to be inserted into):
FollowupNotesSubform
Sub Form Name Table: FollowupNotes

FollowupNotes Table Field Info:

Call ID - Autonumber -
Contact ID - Number - Long Integer - Long Integer - prim key - used as
relation to main Customer database
Call Date - Date/Time - Short date
Call Time - Date/Time - Short date
Subject - Memo
Read - Yes/No

Is this all what you needed?

Thanks
Curtis
 
S

strive4peace

Hi Curtis,

'~~~~~~~~~~~~~~~~
dim strSQL as string

strSQL = "INSERT INTO [FollowupNotes] " _
& "([Contact ID], [Call Date], [Call Time], "
& " [Subject], [Read]) " _
& " SELECT [Contact ID_controlname], " _
& "#" & "[Call Date_controlname] & "#, " _
& "#" & [Call Time_controlname] & "#, " _
& "'" & [Subject_controlname] & "', " _
& "False;"

debug.print strSQL
currentdb.execute strSQL, dbFailOnError

currentdb.tabledefs.refresh
DoEvents

me.FollowupNotesSubform.form.requery

'~~~~~~~~~~~~~~~~

I am assuming Read is False and its value does not come from a control

you will need to make the appropriate substitutions for the controlnames
where the other information comes from

I am assuming that you are in the code behind the form with the
information and that FollowupNotesSubform is a subform of the form you
are on.


'~~~~~~~~~~~~~~~~

** debug.print ***

debug.print strSQL

--> this prints a copy of the SQL statement to the debug window (CTRL-G)

After you execute your code, open the Debug window
CTRL-G to Goto the debuG window -- look at the SQL statement

If the SQL statement has an error

1. Make a new query (design view)

2. choose View, SQL from the menu
(or SQL from the toolbar, first icon)

3. cut the SQL statement from the debug window
(select, CTRL-X)

4. paste into the SQL window of the Query
(CTRL-V)

5. run ! from the SQL window
-- Access will tell you where the problem is in the SQL

'~~~~~~~~~~~~~~


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*



Curtis said:
so are you wanting to create a new record? If so, it would be best to
use an APPEND query to add a record and fill the information -- please
provide the the fieldnames to fill out in your [Followup Notes] table,
their data types, the linking field name(s), and the control name for
the linking field.

After the record is added, you will need to requery the subform --
please provide the relative path from where you are for the subform --
is it a subform directly? Or is it a subform of a subform?

Form POTENTIAL has the button to click that performs the Action. It is a
subform of the main form - Customer Management Screen

Sub Form Name (has the table where I want the record to be inserted into):
FollowupNotesSubform
Sub Form Name Table: FollowupNotes

FollowupNotes Table Field Info:

Call ID - Autonumber -
Contact ID - Number - Long Integer - Long Integer - prim key - used as
relation to main Customer database
Call Date - Date/Time - Short date
Call Time - Date/Time - Short date
Subject - Memo
Read - Yes/No

Is this all what you needed?

Thanks
Curtis
 
G

Guest

'~~~~~~~~~~~~~~~~
dim strSQL as string

strSQL = "INSERT INTO [FollowupNotes] " _
& "([Contact ID], [Call Date], [Call Time], "
& " [Subject], [Read]) " _
& " SELECT [Contact ID_controlname], " _
& "#" & "[Call Date_controlname] & "#, " _
& "#" & [Call Time_controlname] & "#, " _
& "'" & [Subject_controlname] & "', " _
& "False;"

debug.print strSQL
currentdb.execute strSQL, dbFailOnError

currentdb.tabledefs.refresh
DoEvents

me.FollowupNotesSubform.form.requery

'~~~~~~~~~~~~~~~~

I did this, put it all on one line and deleted the _ but it gave me the
error saying Complie Error: Expected: end of statement and point to the #
after Call Date_controlname

Thanks
Curtis
 
S

strive4peace

Hi Curtis,

it is a good idea to use _

_ is a line continuation symbol and makes your code easier to read --
you need to have a space before the underscore

I see that I forgot to put space underscore after
& "([Contact ID], [Call Date], [Call Time], "
-->
& "([Contact ID], [Call Date], [Call Time], " _


if this doesn't fix it, can you paste in what you changed it to?


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*



Curtis said:
'~~~~~~~~~~~~~~~~
dim strSQL as string

strSQL = "INSERT INTO [FollowupNotes] " _
& "([Contact ID], [Call Date], [Call Time], "
& " [Subject], [Read]) " _
& " SELECT [Contact ID_controlname], " _
& "#" & "[Call Date_controlname] & "#, " _
& "#" & [Call Time_controlname] & "#, " _
& "'" & [Subject_controlname] & "', " _
& "False;"

debug.print strSQL
currentdb.execute strSQL, dbFailOnError

currentdb.tabledefs.refresh
DoEvents

me.FollowupNotesSubform.form.requery

'~~~~~~~~~~~~~~~~

I did this, put it all on one line and deleted the _ but it gave me the
error saying Complie Error: Expected: end of statement and point to the #
after Call Date_controlname

Thanks
Curtis
 
G

Guest

Hi Crystal,

I tried that, copied & pasted it just like it was, comes up with error
after error, first one says Expected: line number or lebel or statement or
end of statement on & right before SUBJECT.....

Curtis
 
G

Guest

That didn't work. Here is the code I used. Still says error on the # symbol
where I mentioned it. Also having a brain fart, but when you say change the
control name, you mean "Contact ID" is the control name right?

----------------

Dim strSQL As String

strSQL = "INSERT INTO [Followup Notes] " _
& "([Contact ID], [Call Date], [Call Time], " _
& " [Subject], [Read]) " _
& " SELECT [Contact ID_controlname], " _
& "#" & "[Call Date_controlname] & "#, " _
& "#" & [Call Time_controlname] & "#, " _
& "'" & [Subject_controlname] & "', " _
& "False;"

Debug.Print strSQL
CurrentDb.Execute strSQL, dbFailOnError

CurrentDb.tabledefs.Refresh
DoEvents

Me.Followup_Notes_Subform.Form.Requery
 
S

strive4peace

Hi Curtis,

you need to substitute the NAME for your controls for:

[Contact ID_controlname]
[Call Date_controlname]
[Call Time_controlname]
[Subject_controlname]

I do not have a copy of your database, I have no idea what your control
names are...

~~~~ Properties and Methods ~~~~

Just like in the real world, every object has properties and methods.

Properties are like adjectives that describe an object
Methods are like verbs and define actions an object can do

For instance, you are a human and have properties such as hair color,
eye color, height, weight, ... and methods such as eat, walk, run, jump,
.... make babies -- Add to a collection :)

If you become familiar with the different types of objects that Access
can use and the properties that define them and the methods they can do
(and what triggers them), you will be on your way!

In the design view, you can show the property sheet, which will show
information for the selected item(s).

~~~~ turn on Properties window ~~~~

When you are in the design view, turn on/off the Properties window -->

1. from menu: View, Properties
OR
2. right-click and choose Properties from the shortcut menu

and then click on various objects. The properties window changes as you
change what is selected. If you have multiple objects selected, the
values for the properties they have in common will be displayed

Try it!

~~~~ setting Properties vs. resizing with handles ~~~~

I like to make the width of controls exact -- like 0.25, 0.3, 0.4, 0.5,
0.6, 0.75, 1, 1.25, etc

This is especially handing for lining up labels to controls under them

~~~~ selecting objects ~~~~

you can select multiple controls
1. click and drag the mouse and everything your imaginary rectangle
touches before you let go will be selected
OR
2. click, shift-click, etc
shift-click actually toggles the select status without affecting the
other items selected
OR
3. click (optionally, and drag) in a ruler
while the mouse is down, you will see a line extend across (vertical
ruler) or down (horizontal ruler)
if you click and drag, the ruler will turn dark indicating where you
started and stopped
-- everything the line/rectangle touches will be selected
OR
4. drop down the objects combo (left-most control on design toolbar) and
select something by its name

~~~~ select Form or Report ~~~~

To select the form (or report), you may:

1. click in the upper left corner where the rulers intersect
OR
2. click completely outside the designed area in the dark gray space
OR
3. press CTRL-R
OR
4. from menu: Edit, Select Form/Report

~~~~ building event code ~~~

To build an event, click in the property sheet for the appropriate
object in the appropriate location and then click the builder (...)
button off to the right

Access will provide the procedure declaration and the procedure end --
you put the lines in between.

~~~~ Name property ~~~~

Procedures are NAMED according to the object name (except the form
object), so ALWAYS change the NAME property of any object to something
logical.

When the properties window is displayed and only one thing is selected,
the Name appears in the title bar of the Properties window

If multiple items are selected, you will see "Multiple Selection" on the
title bar

~~~~ ControlSource, SourceObject ~~~~

It is important to realize that the Name is NOT what is displayed in a
control. If the control is (for instance a textbox or combo box), you
will see the ControlSource displayed.

If the object is (for instance) a subform or subreport, what you see
displayed is the SourceObject

For bound objects, I like to make the Name property match the source
property (this does not, btw, follow naming conventions, but for me, it
eases confusion)

As always, avoid using spaces and special characters when naming objects
-- use the underscore character _ to separate and use mixed case for
readability

~~~~ Recordset Property ~~~~

from the design view of a report or form:

turn on Properties
(from menu: View, Properties)

select the report or form
(click in the upper left where the rulers intersect)

click on the Data tab in Properties window

there you will see the RecordSet property
once you click in the property, you will see the builder button ... to
the right

If your report is based on a query, this takes you to the query design
screen

If your report is based on a SQL statement, you can modify it like the
design view of a query (you can also press SHIFT-F2 to use the Zoom Box
to change the SQL)

If your report is based on a table, you will be asked if you want to
make a query

~~~~ Builder Button ~~~~

The RowSource property for a combo or list box is like the RecordSource
property for a form or report -- you are choosing where the data will
come from that is displayed. The Builder Button ... will be displayed
when you click IN the property.

For choosing colors that are not on the color palette (like ForeColor,
BackColor, Bordercolor), click the builder button. Once in the palette
dialog box, click "Define Custom Colors" -- the dialog box will expand
and you can set the amounts for Red/Green/Blue or adjust
Hue/Saturation/Luminosity. There is also a slider control with a
triangle you can drag up or down to change the Luminosity (brightness).
I like to drag it up and fade out colors, especially for BackColor.

~~~~ Events ~~~~

"Properties" listed on the Events tab are actually methods ... such as
OnCurrent for form, AfterUpdate for Control, etc

~~~~ Learning the properties ~~~~

Explore the property sheet. Get familiar with how properties are
grouped on the tabs and the different properties for different objects.

~~~~ Help on Properties ~~~~

You can get help about any property by pressing F1 while in a property
on the property sheet where you want more information.

~~~~ Object Browser ~~~~

.... find out more about references... or just get Help!

in a code window to View the Object Browser:
1. from the menu --> View, Object Browser
OR
2. Press F2

On the left, you will probably see a Project window and a Properties
window below it
On the right, you will see the main Object Browser window

as you select a Class on the left, its members will appear in the pane
on the right

when you see something you want help on, press the F1 key and switch to
the Help window

When you are getting started, change the library to "VBA" (for instance,
instead of <all libraries>) and look at the classes (categories) of
functions -- click on a class and then click on a function in the right
pane. To get the help for that function, press F1

The VBA library is the most basic library and a great place to start
exploring.

To look up properties and methods for different objects like forms,
tabledefs, etc, change the library to Access
To look up ranges and sheets, change the library to Excel

explore the different libraries you have to pick from and see what is
available in each
(these are added or removed using Tools, References...)

when you are in the Object Browser window, the library that each
function/class is a member of is shown in the lower left corner of the
window

when you have an object selected, press F1 to get help.

~~~~ general help ~~~~

For general help, I find it interesting and informative to read the help
starting from the beginning of the Contents. In fact, if you have the
desire to print a ream of paper, it would be good to print it like a
book and read it so you can also take notes -- and you can read it away
from the computer -- a good time to put new information into your head
is just before you sleep ... let your subconscious figure it out!


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*



Curtis said:
That didn't work. Here is the code I used. Still says error on the # symbol
where I mentioned it. Also having a brain fart, but when you say change the
control name, you mean "Contact ID" is the control name right?

----------------

Dim strSQL As String

strSQL = "INSERT INTO [Followup Notes] " _
& "([Contact ID], [Call Date], [Call Time], " _
& " [Subject], [Read]) " _
& " SELECT [Contact ID_controlname], " _
& "#" & "[Call Date_controlname] & "#, " _
& "#" & [Call Time_controlname] & "#, " _
& "'" & [Subject_controlname] & "', " _
& "False;"

Debug.Print strSQL
CurrentDb.Execute strSQL, dbFailOnError

CurrentDb.tabledefs.Refresh
DoEvents

Me.Followup_Notes_Subform.Form.Requery
 
G

Guest

When you say controlname, you are talking about the name of the field in the
table, then yes, those are it. You asked for them previously and I gave you
the full details. I changed that accordingly and it still doesn't work, I
get that error I mentioned previously.....

Also, where is the text that will be inserted should go or be?

Curtis
 
S

strive4peace

Hi curtis,

no, NOT the name of the field in the table -- that is the ControlSource
property...Name and ControlSource are 2 distinct properties and may not
necessarily be the same... ControlSource is what is diaplayed in the
control when you are looking at the design, so it can be confusing.
Read the Properties and Methods text I pasted into my last reply.

when you are in the design view of your form,
from the menu, choose: View, Properties

then click on a control

the Properties window will show properties of the selection

click on the Other or All tab in the properties window -- the Name
property is listed on top -- and you can also change what it says if it
ambiguous. I like to make the Name and the ControlSource property the
same for bound controls to ease confusion

"Also, where is the text that will be inserted should go or be?"

not sure what you mean by this... are you referring to the code?

Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*
 
D

Douglas J. Steele

In addition to the advice you're getting from Crystal, your quotes are
wrong. Specifically, you've got an unnecessary double quote in front of
[Call Date_controlname], and [Contract ID_controlname] shouldn't be in
quotes. As well, since you're trying to insert a specific set of values
(rather than a subset of values from another table), you shouldn't be using
the INSERT INTO ... SELECT construct: you should be using the INSERT INTO
.... VALUES construct:

strSQL = "INSERT INTO [Followup Notes] " _
& "([Contact ID], [Call Date], [Call Time], " _
& " [Subject], [Read]) " _
& " VALUES ( " & [Contact ID_controlname] & ", " _
& "#" & [Call Date_controlname] & "#, " _
& "#" & [Call Time_controlname] & "#, " _
& "'" & [Subject_controlname] & "', " _
& "False)"

As well, since you cannot be sure of what your users have their Short Date
and Short Time formats set to, it's prudent to force the date and time
values into formats with which Access will work correctly:

strSQL = "INSERT INTO [Followup Notes] " _
& "([Contact ID], [Call Date], [Call Time], " _
& " [Subject], [Read]) " _
& " VALUES ( " & [Contact ID_controlname] & ", " _
& Format(CDate([Call Date_controlname]), "\#mm\/dd\/yyyy\#") &", " _
& Format(CDate([Call Time_controlname]), "\#hh\:nn\:ss\#") & ", " _
& "'" & [Subject_controlname] & "', " _
& "False)"

Finally, it's FAR better to combine date and time into a single field,
rather than store them in separate fields. Should you only require the date
portion or the time portion at some point, you can use the DateValue or
TimeValue functions to extract those specific parts.
 
G

Guest

1. Where do I put the text I want inserted into the code, where in the code?
That is the whole purpose of this, is to insert some specific text.....

2. I tried yours and it says: Run-time error '2465" MA can't find the
field "|" referred to in your expression.

In case you need it, here is the code I have as the onclick:

==========CODE=============
Private Sub Decals___Signage_Sent_Click()
Dim strSQL As String

strSQL = "INSERT INTO [Followup Notes] " _
& "([Contact ID], [Call Date], [Call Time], " _
& " [Subject], [Read]) " _
& " VALUES ( " & [Contact ID] & ", " _
& Format(CDate([Call Date]), "\#mm\/dd\/yyyy\#") & ", " _
& Format(CDate([Call Time]), "\#hh\:nn\:ss\#") & ", " _
& "'" & [Subject] & "', " _
& "False)"

Debug.Print strSQL
CurrentDb.Execute strSQL, dbFailOnError

CurrentDb.tabledefs.Refresh
DoEvents

Me.Followup_Notes_Subform.Form.Requery

End Sub
============CODE===========

Thanks
Curtis


In addition to the advice you're getting from Crystal, your quotes are
wrong. Specifically, you've got an unnecessary double quote in front of
[Call Date_controlname], and [Contract ID_controlname] shouldn't be in
quotes. As well, since you're trying to insert a specific set of values
(rather than a subset of values from another table), you shouldn't be using
the INSERT INTO ... SELECT construct: you should be using the INSERT INTO
.... VALUES construct:

strSQL = "INSERT INTO [Followup Notes] " _
& "([Contact ID], [Call Date], [Call Time], " _
& " [Subject], [Read]) " _
& " VALUES ( " & [Contact ID_controlname] & ", " _
& "#" & [Call Date_controlname] & "#, " _
& "#" & [Call Time_controlname] & "#, " _
& "'" & [Subject_controlname] & "', " _
& "False)"

As well, since you cannot be sure of what your users have their Short Date
and Short Time formats set to, it's prudent to force the date and time
values into formats with which Access will work correctly:

strSQL = "INSERT INTO [Followup Notes] " _
& "([Contact ID], [Call Date], [Call Time], " _
& " [Subject], [Read]) " _
& " VALUES ( " & [Contact ID_controlname] & ", " _
& Format(CDate([Call Date_controlname]), "\#mm\/dd\/yyyy\#") &", " _
& Format(CDate([Call Time_controlname]), "\#hh\:nn\:ss\#") & ", " _
& "'" & [Subject_controlname] & "', " _
& "False)"

Finally, it's FAR better to combine date and time into a single field,
rather than store them in separate fields. Should you only require the date
portion or the time portion at some point, you can use the DateValue or
TimeValue functions to extract those specific parts.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Curtis Stevens said:
That didn't work. Here is the code I used. Still says error on the #
symbol
where I mentioned it. Also having a brain fart, but when you say change
the
control name, you mean "Contact ID" is the control name right?

----------------

Dim strSQL As String

strSQL = "INSERT INTO [Followup Notes] " _
& "([Contact ID], [Call Date], [Call Time], " _
& " [Subject], [Read]) " _
& " SELECT [Contact ID_controlname], " _
& "#" & "[Call Date_controlname] & "#, " _
& "#" & [Call Time_controlname] & "#, " _
& "'" & [Subject_controlname] & "', " _
& "False;"

Debug.Print strSQL
CurrentDb.Execute strSQL, dbFailOnError

CurrentDb.tabledefs.Refresh
DoEvents

Me.Followup_Notes_Subform.Form.Requery
 
D

Douglas J. Steele

1) I believe Crystal assumed (as did I) that you were putting the data to be
entered in text boxes on your form. If that's the case, let's assume that
the text boxes on your form are named txtContactID, txtCallDate, txtCallTime
and txtSubject. You'd change the code you've got to:

strSQL = "INSERT INTO [Followup Notes] " _
& "([Contact ID], [Call Date], [Call Time], " _
& " [Subject], [Read]) " _
& " VALUES ( " & Me.txtContactID & ", " _
& Format(CDate(Me.txtCallDate), "\#mm\/dd\/yyyy\#") & ", " _
& Format(CDate(Me.txtCallTime), "\#hh\:nn\:ss\#") & ", " _
& "'" & Me.txtSubject & "', " _
& "False)"

If you're not putting the text in controls on the form, how do you want to
get it from the user?

2) The failure's likely happening since you're not giving actual values to
the SQL. Once you make the correction above, if it's still not working,
what's being written to the Immediate Window by your Debug.Print strSQL line
of code?


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Curtis Stevens said:
1. Where do I put the text I want inserted into the code, where in the
code?
That is the whole purpose of this, is to insert some specific text.....

2. I tried yours and it says: Run-time error '2465" MA can't find the
field "|" referred to in your expression.

In case you need it, here is the code I have as the onclick:

==========CODE=============
Private Sub Decals___Signage_Sent_Click()
Dim strSQL As String

strSQL = "INSERT INTO [Followup Notes] " _
& "([Contact ID], [Call Date], [Call Time], " _
& " [Subject], [Read]) " _
& " VALUES ( " & [Contact ID] & ", " _
& Format(CDate([Call Date]), "\#mm\/dd\/yyyy\#") & ", " _
& Format(CDate([Call Time]), "\#hh\:nn\:ss\#") & ", " _
& "'" & [Subject] & "', " _
& "False)"

Debug.Print strSQL
CurrentDb.Execute strSQL, dbFailOnError

CurrentDb.tabledefs.Refresh
DoEvents

Me.Followup_Notes_Subform.Form.Requery

End Sub
============CODE===========

Thanks
Curtis


In addition to the advice you're getting from Crystal, your quotes are
wrong. Specifically, you've got an unnecessary double quote in front of
[Call Date_controlname], and [Contract ID_controlname] shouldn't be in
quotes. As well, since you're trying to insert a specific set of values
(rather than a subset of values from another table), you shouldn't be
using
the INSERT INTO ... SELECT construct: you should be using the INSERT INTO
.... VALUES construct:

strSQL = "INSERT INTO [Followup Notes] " _
& "([Contact ID], [Call Date], [Call Time], " _
& " [Subject], [Read]) " _
& " VALUES ( " & [Contact ID_controlname] & ", " _
& "#" & [Call Date_controlname] & "#, " _
& "#" & [Call Time_controlname] & "#, " _
& "'" & [Subject_controlname] & "', " _
& "False)"

As well, since you cannot be sure of what your users have their Short
Date
and Short Time formats set to, it's prudent to force the date and time
values into formats with which Access will work correctly:

strSQL = "INSERT INTO [Followup Notes] " _
& "([Contact ID], [Call Date], [Call Time], " _
& " [Subject], [Read]) " _
& " VALUES ( " & [Contact ID_controlname] & ", " _
& Format(CDate([Call Date_controlname]), "\#mm\/dd\/yyyy\#") &", " _
& Format(CDate([Call Time_controlname]), "\#hh\:nn\:ss\#") & ", " _
& "'" & [Subject_controlname] & "', " _
& "False)"

Finally, it's FAR better to combine date and time into a single field,
rather than store them in separate fields. Should you only require the
date
portion or the time portion at some point, you can use the DateValue or
TimeValue functions to extract those specific parts.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


message
That didn't work. Here is the code I used. Still says error on the #
symbol
where I mentioned it. Also having a brain fart, but when you say
change
the
control name, you mean "Contact ID" is the control name right?

----------------

Dim strSQL As String

strSQL = "INSERT INTO [Followup Notes] " _
& "([Contact ID], [Call Date], [Call Time], " _
& " [Subject], [Read]) " _
& " SELECT [Contact ID_controlname], " _
& "#" & "[Call Date_controlname] & "#, " _
& "#" & [Call Time_controlname] & "#, " _
& "'" & [Subject_controlname] & "', " _
& "False;"

Debug.Print strSQL
CurrentDb.Execute strSQL, dbFailOnError

CurrentDb.tabledefs.Refresh
DoEvents

Me.Followup_Notes_Subform.Form.Requery
 

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