Update after delete, how?

M

Marcello

Hi everyone,
I'm using Access2003 and I have a problem with an update-after-delete
condition.


Private Sub DESCRIPTION_AfterUpdate()
Dim blnFlag As Boolean

If Me!DESCRIPTION.Column(1) Like "A" Then
blnFlag = True
End If

Forms("Form1").A1.Visible = blnFlag
Forms("Form1").B1.Visible = Not blnFlag
Forms("Form1").A2.Visible = blnFlag
Forms("Form1").B2.Visible = Not blnFlag
End Sub


I created a form with a subform. In the subform I realized a combo
with 2 descriptions: A and B. The selection of A or B influences the
visibility of a couple of buttons on the form.
Everything works fine as long as I just type A or B, but if I delete
the last input, the form doesn't update to the right value, but keeps
stuck to the last value typed.

Question: Do you know what should I do to implement this update-after-delete
condition?

Thank you all for your time and consideration.
M.
 
M

Mike Painter

Marcello said:
Hi everyone,
I'm using Access2003 and I have a problem with an update-after-delete
condition.


Private Sub DESCRIPTION_AfterUpdate()
Dim blnFlag As Boolean

If Me!DESCRIPTION.Column(1) Like "A" Then
blnFlag = True
End If

Forms("Form1").A1.Visible = blnFlag
Forms("Form1").B1.Visible = Not blnFlag
Forms("Form1").A2.Visible = blnFlag
Forms("Form1").B2.Visible = Not blnFlag
End Sub


I created a form with a subform. In the subform I realized a combo
with 2 descriptions: A and B. The selection of A or B influences the
visibility of a couple of buttons on the form.
Everything works fine as long as I just type A or B, but if I delete
the last input, the form doesn't update to the right value, but keeps
stuck to the last value typed.

Question: Do you know what should I do to implement this
update-after-delete condition?

Thank you all for your time and consideration.
M.

It's not exactly clear what you mean by deleting the last input but your
results will always bwe teh samwe no matter what you type.
Something like
If Me!DESCRIPTION.Column(1) Like "A" Then
blnFlag = True
Forms("Form1").A1.Visible = blnFlag
Forms("Form1").B1.Visible = Not blnFlag
Forms("Form1").A2.Visible = blnFlag
Forms("Form1").B2.Visible = Not blnFlag
else
Forms("Form1").A1.Visible = False
Forms("Form1").B1.Visible = True
Forms("Form1").A2.Visible = False
Forms("Form1").B2.Visible = True
end if.

I use True and False as it seems much clearer to me.

Alos note that "A" will get you what you want for "A" but anything else
will get ehat you want for "B"

I'd probably use a case statement.
 
M

Marcello

Mike Painter said:
It's not exactly clear what you mean by deleting the last input but your
results will always bwe teh samwe no matter what you type.
Something like
If Me!DESCRIPTION.Column(1) Like "A" Then
blnFlag = True
Forms("Form1").A1.Visible = blnFlag
Forms("Form1").B1.Visible = Not blnFlag
Forms("Form1").A2.Visible = blnFlag
Forms("Form1").B2.Visible = Not blnFlag
else
Forms("Form1").A1.Visible = False
Forms("Form1").B1.Visible = True
Forms("Form1").A2.Visible = False
Forms("Form1").B2.Visible = True
end if.

I use True and False as it seems much clearer to me.

Alos note that "A" will get you what you want for "A" but anything else
will get ehat you want for "B"

I'd probably use a case statement.
Thanks Mike, I tried your condition and I keep missing something.
What I'd like to get is the track of the last input. Let me explain this
thing better.

With your condition it works fine only when the previous line typed is B
'cause
the present line, still blank, is considered in the "else" condition.
Instead, I'd like to have a condition that adjusts the flag visibility based
on the last line typed.
The marker ">" indicates the present line to be typed.

A A
B B
A >
button A button B

Thanks again,
Marcello.
 
M

Mike Painter

Marcello said:
Thanks Mike, I tried your condition and I keep missing something.
What I'd like to get is the track of the last input. Let me explain
this thing better.

With your condition it works fine only when the previous line typed
is B 'cause
the present line, still blank, is considered in the "else" condition.
Instead, I'd like to have a condition that adjusts the flag
visibility based on the last line typed.
The marker ">" indicates the present line to be typed.

A A
B B
A >

button A button B

Thanks again,
Marcello.

What do you mean when you say "line"?
Is this a database row or record?
Are the "A" and "B" entered into the same field or column of the record?

If the "last lime" refers to a previous record then you will have to save
that state.
AfterUpdate does not affect the next record.
 
M

Marcello

Mike Painter said:
What do you mean when you say "line"?
Is this a database row or record?
Are the "A" and "B" entered into the same field or column of the record?

If the "last lime" refers to a previous record then you will have to save
that state.
AfterUpdate does not affect the next record.

Actually you're right, I mean record.
Yes, "A" and "B" are entered in the same column of the record and what I
would like to do precisely is to save the state, but I don't know how.
The code is placed in AfterUpdate of the form and into Current of the
subform.

thank you again,
Marcello
 
M

Mike Painter

Marcello said:
Actually you're right, I mean record.
Yes, "A" and "B" are entered in the same column of the record and
what I would like to do precisely is to save the state, but I don't
know how. The code is placed in AfterUpdate of the form and into
Current of the subform.

thank you again,
Marcello

Dlast is probably as good a way as any.
http://www.techonthenet.com/access/functions/domain/dlast.php

In the onCurrent event for the new record something like
Me.MyField = dLast("MyField", "YourTableName")
 
M

Marcello

Mike Painter said:
Dlast is probably as good a way as any.
http://www.techonthenet.com/access/functions/domain/dlast.php

In the onCurrent event for the new record something like
Me.MyField = dLast("MyField", "YourTableName")

Dear Mike,
I wrote this:

Dim blnFlag As Boolean
Dim pippo As String

pippo = DLast("DESCRIPTION", "TbDescription")

If pippo Like "A" Then
blnFlag = True
Forms("Form1").A1.Visible = blnFlag
Forms("Form1").B1.Visible = Not blnFlag
Forms("Form1").A2.Visible = blnFlag
Forms("Form1").B2.Visible = Not blnFlag
End If
If pippo Like "B" Then
Forms("Form1").A1.Visible = False
Forms("Form1").B1.Visible = True
Forms("Form1").A2.Visible = False
Forms("Form1").B2.Visible = True
End If

and it does what I want except when I delete the last records (1 or more..)
In that case this code cannot update the buttons to the right configuration.
Since DLast is reading the last typed, but not the last record (I mean the
last you still
have in the table), right?
That brings me to the problem that I had when I asked for a help on this
forum.

Have a good week-end Mike,
Marcello
 
M

Marcello

Marcello said:
Dear Mike,
I wrote this:

Dim blnFlag As Boolean
Dim pippo As String

pippo = DLast("DESCRIPTION", "TbDescription")

If pippo Like "A" Then
blnFlag = True
Forms("Form1").A1.Visible = blnFlag
Forms("Form1").B1.Visible = Not blnFlag
Forms("Form1").A2.Visible = blnFlag
Forms("Form1").B2.Visible = Not blnFlag
End If
If pippo Like "B" Then
Forms("Form1").A1.Visible = False
Forms("Form1").B1.Visible = True
Forms("Form1").A2.Visible = False
Forms("Form1").B2.Visible = True
End If

and it does what I want except when I delete the last records (1 or
more..)
In that case this code cannot update the buttons to the right
configuration.
Since DLast is reading the last typed, but not the last record (I mean the
last you still
have in the table), right?
That brings me to the problem that I had when I asked for a help on this
forum.

Have a good week-end Mike,
Marcello

Dear Mike,

I hope this email finds you very well.

I found a solution to that problem,
actually all it took was an update query
put into the Sub Form_AfterDelConfirm,
and of course, your suggestion to use DLast.

Thank yo very much again,
Marcello.
 

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