replace function

C

clara

I need to replace a date in one table of my database. I made the following
code: Dim ApptDate As String
ApptDate = Replace("Forms!ModificarFecha!FechaActual",
"Forms!ModificarFecha!NuevaFecha")
It doesn´t work. The message is: it´s not an optional argument. Please, Help.
 
D

Douglas J. Steele

What are you hoping that statement will do?

The syntax for the Replace function is:

Replace(expression, find, replace[, start[, count[, compare]]])

The Replace function syntax has these named arguments:

expression Required String expression containing substring to replace.
find Required Substring being searched for.
replace Required Replacement substring.
start Optional Position within expression where substring
search is to begin. If omitted, 1 is assumed.
count Optional Number of substring substitutions to perform. If
omitted, the default is -1, which means make all possible substitutions.
compare Optional Numeric value indicating the kind of comparison to
use when evaluating substrings. See Settings section for values.

It strictly works on strings, not on tables.
 
J

John Vinson

I need to replace a date in one table of my database. I made the following
code: Dim ApptDate As String
ApptDate = Replace("Forms!ModificarFecha!FechaActual",
"Forms!ModificarFecha!NuevaFecha")
It doesn´t work. The message is: it´s not an optional argument. Please, Help.

If you are trying to change the value of a field stored in a Table,
the Replace function is *not* the correct tool. Use an Update query
instead. You will need to specify which record in the table should
have its field changed.

Note also that data is NOT stored in Forms, as your example seems to
suggest. Data is stored in Tables, and only in Tables. You can set the
value of a Control on a form (which will update that control's Control
Source field); perhaps all you need to do is

Forms!ModificarFecha!FechaActual = Forms!ModificarFecha!NuevaFecha

or, if the code is actually running on the form ModificarFecha, use
the shortcut:

Me!FechaActual = Me!NuevaFecha

John W. Vinson[MVP]
 
Top