How to copy a date depending on....

  • Thread starter Thread starter MyVi
  • Start date Start date
M

MyVi

Hi everyone.
How would you help me with this please?

Here there is a MDB with the simple problem. This MDB has nothing else
but the stuff to solve the problem (to build the specific code to make
it work)
http://www.easy-sharing.com/63046/Copia de fechas.mdb.html


As you can see, there is a Query [cCOPIA] with 2 filds: [FechaOrigen] &
[Grupo].
In a FORM I have 2 TextBox one for each Query's fields.

What I need to do is to input a DATE into the TextBox of the
[FechaOrigen] and to see the nº you have in [Grupo] and to copy the
same DATE in the [FechaOrigen] in all those cells where in [Grupo] you
have the same nº.
What this is, simply, is that I have several things in the GROUP 3 and
when I am in one of those things.. and I put a DATE, I want this date
to be copied in the other cells of the same GROUP. That's it.

Well, so far I am trying to do so with this CODE (you can check it
out).

Private Sub Texto3_AfterUpdate()
Dim stSQL As String
stSQL = "UPDATE cCOPIA SET cCOPIA.FechaOrigen = " & Me.FechaOrigen & "
WHERE (((cCOPIA.Grupo) =" & Me.Grupo & "));"
CurrentDb.Execute stSQL
End Sub

But I am no really good on coding and I just got this not really
working.
Could anyone try to help me solve it, please?

If you get the MDB file, you have the fast and easy oportunity to check
the problem and to find out the solution.

http://www.easy-sharing.com/63046/Copia de fechas.mdb.html


Thank you.

Vic
 
Vic,

Try it like one of these...

stSQL = "UPDATE cCOPIA SET FechaOrigen = " & CLng(Me.FechaOrigen) & "
WHERE Grupo =" & Me.Grupo

stSQL = "UPDATE cCOPIA SET FechaOrigen = #" & Me.FechaOrigen & "#
WHERE Grupo =" & Me.Grupo

stSQL = "UPDATE cCOPIA SET FechaOrigen = " &
Format(Me.FechaOrigen,"#mm/dd/yy#") & " WHERE Grupo =" & Me.Grupo

The 1st or the 3rd approach will be best if your local date format is
not American format.
 
Steve,
did it work to you? I mean, did you take the MDB file and used that
code and did work to you?.
Well, it didn't in mine. I've tried all these 3 options, and nothing.
I've got some problems at first with writing the code (it got the
sentence red color) but at last I've got it not red (supposed working)
but did not work when I tried to input the date.

Donno what else do. I get an error but donno how to solve it.

Vic
 
Vic,

What actually happens when you try to run this? Is there an error
message? What does it say? What is Texto3?
 
Steve,
I've done some modifications on your original CODE (with some more help
around) and now it works, but there is a problem with the format date.
I mean, I input an dd/mm/yy and it gets to dd/mm/yyyy (when I see it)
but when it makes teh copy the copied date is mm/dd/yyyy instead.
Well, it works, definitively, but I would need the format date as
dd/mm/yyyy instead.

I'm gonna try to get some solution about this issue. I think it won't
be that dificult.

Private Sub Form_AfterUpdate()
Dim stSQL As String
stSQL = "UPDATE tCOPIA SET tCOPIA.FechaOrigen = #" & Me.FechaOrigen &
"#
WHERE (((tCOPIA.Grupo) ='" & Me.Grupo & "'));"
CurrentDb.Execute stSQL
End Sub

Thank you

Vic
 
Steve, I've solved.

This is what I've done and it is working:


Private Sub Texto3_AfterUpdate()
Me.Refresh
Dim stSQL As String
Dim k
k = Year(Me.Texto3) & "/" & Month(Me.Texto3) & "/" & Day(Me.Texto3)
stSQL = "UPDATE tCOPIA SET tCOPIA.FechaOrigen = #" & k & _
"# WHERE (((tCOPIA.Grupo) ='" & Me.Grupo & "'));"
CurrentDb.Execute stSQL
End Sub

Great. Now just we have to know (you knew it, but I didn't) that we
can't erase a DATE but left it there.
So no problem for my needs.

Thank you so much to everyone.

Vic
 
Vic,

I'm pleased you have it working. You have solved it in a difficult way,
and I am not sure why you didn't follow my suggestions. I would still
just go like this...
stSQL = "UPDATE cCOPIA SET FechaOrigen = " & CLng(Me.Texto3) & " WHERE
Grupo =" & Me.Grupo
 
Back
Top