Unable to call functions in AfterUpdate

  • Thread starter edisonl via AccessMonster.com
  • Start date
E

edisonl via AccessMonster.com

Hi,

This is a strange encounter, I tried to call up a function in event handler
but unable to, more elaborations below.

private sub Password_AfterUpdate()
{
dim rd as adodb.recordset
dim conn as adodb.connection
set rd = .....
set conn = ...
rd.open "employee_table", . . ., . . .
rd.filter . . .

if(Password = rd!password)then
cancelrecord

else
msgbox "invalid password"

endif
}
end sub //end password_afterupdate
// __________________________________
private sub cancel()
{
dim rd as adodb.recordset
dim conn as adodb.connection
set rd = .....
set conn = ...
rd.open "transactions_table", . . ., . . .
rd.filter . . .

msgbox "inside cancel function"

if(transaction_subform!transaction_id = rd!transactionid)then
rd!balance = transaction_subform!taken + rd!balance //restore taken value
to balance
rd!taken = rd!taken - transaction_subform!taken //offset taken
value
else
msgbox "invalid password"
endif

}
end sub //end cancel
_________________________________________________________________________

PROBLEM: a print statement in cancel function is able to generate the output
but
when added the line of rd.open ... cancel() is unable to fire off.

Steps done:
1. Tried changing variables names from rd> rds, conn> con (still unable to
call cancel function)
2. Tried eliminate conn using only rd/rds (still unable to call cancel
function)

Anyone can shed some light ?

Regards & God Bless, Edison
 
J

June7 via AccessMonster.com

What you show here are Sub procedures, not functions. What function do you
want to call? I see you name a procedure Password and then within the
procedure call Password. The procedure is calling itself? Don't see that
'cancelrecord' will do anything.
Would like to see your complete string for opening the recordset. Could be
DLookup would serve just as well in place of the connection and recordset
code.

Also, you are using punctuation I have not seen in Access VBA code. Ex. the
braces ({}) and slash (/) marks. Is this Access VBA code?
 
E

edisonl via AccessMonster.com

Hi June7,

Thanks for replying . . . here it goes.
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
'Password_Text_AfterUpdate
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Private Sub Password_Text_AfterUpdate()
'On Error GoTo Err_password_text_afterupdate

Dim Password As String
Dim rd As ADODB.Recordset
Dim conn As ADODB.Connection
Dim table, strsql As String
Set rd = New ADODB.Recordset
Set conn = CurrentProject.Connection

rd.Open "Personnel_Table", conn, adOpenStatic
rd.Filter = "Name='" & Transaction_Subform!Name & "'"

If (Transaction_Subform!Name = rd!Name And Password_Text = rd!Password) Then
Password_Text = ""
rd.Close
conn.Close
Set rd = Nothing
Set conn = Nothing

If (choice = "Cancel") Then
'** ** ** ** ** ** ** ** ** **
MsgBox "Calling cancelleave()..."
cancelleave
'** ** ** ** ** ** ** ** ** **
MsgBox "Transactions Cancelled"
Transaction_Subform.SetFocus
DoCmd.Requery
Exit Sub
else
'do nothing
End If // If (choice = "Cancel") Then

End If //Private Sub Password_Text_AfterUpdate()


' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
'Cancel Leave
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Private Sub cancelleave()
'On Error GoTo Err_cancelleave
Dim table, strsql As String
Dim rds As ADODB.Recordset
Dim con As ADODB.Connection

Set rds = New ADODB.Recordset
Set con = CurrentProject.Connection

MsgBox "I am INSIDE CancelLeave()"

If (PendingLeave_Subform!LeaveType = "AnnualLeave" Or _
PendingLeave_Subform!LeaveType = "MedicalLeave" Or _
PendingLeave_Subform!LeaveType = "ChildCareLeave" Or _
PendingLeave_Subform!LeaveType = "CompassionateLeave" Or _
PendingLeave_Subform!LeaveType = "ExamLeave" Or _
PendingLeave_Subform!LeaveType = "HospitalisationLeave") Then

table = PendingLeave_Subform!LeaveType & "Setting_Table"
rds.Open table, con, adOpenStatic
rds.Filter = "UserID='" & UserID_Text & "'"

'Return to Setting Table
If (rds.recordcount > 0) Then
MsgBox "Record count > 0"
rds!taken = rds!taken - PendingLeave_Subform!TotalDays
rds!balance = rd!balance + PendingLeave_Subform!TotalDays
rds.UpdateBatch adAffectCurrent
rds.Close
con.Close
Set rds = Nothing
Set con = Nothing
End If

Regards & God Bless, Edison


- - - - - - - - - - - - - - - -
June7 said:
What you show here are Sub procedures, not functions. What function do you
want to call? I see you name a procedure Password and then within the
procedure call Password. The procedure is calling itself? Don't see that
'cancelrecord' will do anything.
Would like to see your complete string for opening the recordset. Could be
DLookup would serve just as well in place of the connection and recordset
code.

Also, you are using punctuation I have not seen in Access VBA code. Ex. the
braces ({}) and slash (/) marks. Is this Access VBA code?
[quoted text clipped - 57 lines]
Regards & God Bless, Edison
 
E

edisonl via AccessMonster.com

Hi June7,

Guess What ? When I replaced all codes in the cancel leave to just msgbox
"Inside Cancel Leave ()",
not only cancel leave not being called, but the main event handler for
Password_Text AfterUpdate that
is used to trigger CancelLeave() are not being called as well !

What I did was do a msgbox "" after Passwrd_Text AfterUpdate(), and it msgbox
inside AfterUpdate() failed to fire off.

Regards & God Bless, Edison

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - -
What you show here are Sub procedures, not functions. What function do you
want to call? I see you name a procedure Password and then within the
[quoted text clipped - 12 lines]
 

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