Results 1 to 6 of 6
  1. #1
    shah1419 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jan 2013
    Posts
    30

    Form Load Event

    Respected,I have a table name (fee) which have the following fields:it will only send one message and not send other messges which dues is unpaid...please advised. -------------------------------------------------------------------------------------------------------------------------------------GR No: 1, 2,3,4,5,6,7Name: Aslam,Naveed,Wasif,Altaf etcSub Fields: Date, Month, Year, TutFee, Exam, Comp, Other, Payable, Paid, Balance---------------------------------------------------------------------------------------------------------------------------------------i want to send the unpaid dues messges to parents whose dues is not paid afterdate 10-01-2013.i have put the following code in form open event:--------------------------------------------------------------------------------------------------------------------------------------Private Sub Form_Open(Cancel As Integer)On Error GoTo ErrorHandlerDoCmd.SetWarnings FalseDim StrSQl As StringDim a As Datea = DateDim D As IntegerD = Day(a)If D > 10 And Me.Paid = 0 Or Me.Paid = "" ThenDim dbs As Database, rst As RecordsetSet dbs = CurrentDb Set rst = dbs.OpenRecordset("SELECT Fees.* " _& "FROM Fees WHERE [GR No]=" & "" & Me.[GR No] & "" And Me.Paid = 0)If Not rst.EOF ThenMe.T = DLookup("Mobile", "Student", "[GR No]" = "[GR No]")StrSQl = "Insert into MsgOut (iid,msg,send,msgto) values('[GR No]','Respected Parents!Your Child Fees Has Been Due..Please Paid the dues as eraliest...','Yes',T);"DoCmd.RunSQL (StrSQl)End IfEnd IfExitHandleroCmd.SetWarnings TrueExit Sub ErrorHandler:MsgBox Err.Number & Chr(13) & Err.DescriptionResume ExitHandlerEnd Sub -----------------------------------

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It is very difficult to read unformatted code like that, but you want a loop rather than an If/Then block. It would start with

    Do While Not rst.EOF
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    shah1419 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jan 2013
    Posts
    30

    form open event

    i have made some change in that codelease review: For Example: 20 Fees Students are defaulter and only one messge send to one parents. i want to repeat this action 20 or more times(Send ing messge to all parents whose students fees is unpaid). Private Sub Form_Open(Cancel As Integer)Dim Ins As IntegerOn Error GoTo ErrorHandlerDoCmd.SetWarnings FalseDim StrSQl As StringDim a As Datea = DateDim D As IntegerD = Day(a)DoIf D > 10 And Me.Paid = 0 ThenStrSQl = "Insert into MsgOut (iid,msg,send,msgto) values('[GR No]','Respected Parents!Your Child Fees Has Been Due..Please Paid the dues as earliest...','Yes',Mobile);"DoCmd.RunSQL (StrSQl)End IfExit DoLoopExit HandleroCmd.SetWarnings TrueExit SubErrorHandler:MsgBox Err.Number & Chr(13) & Err.DescriptionResume ExitHandler.End Sub

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Can you make it readable?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    shah1419 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jan 2013
    Posts
    30
    Quote Originally Posted by pbaldy View Post
    Can you make it readable?
    I have made some change in that code Please review: For Example: 20 Fees Students are defaulter and only one messge send to one parents. i want to repeat this action 20 or more times(Send ing messge to all parents whose students fees is unpaid). Private Sub Form_Open(Cancel As Integer)Dim Ins As IntegerOn Error GoTo ErrorHandlerDoCmd.SetWarnings FalseDim StrSQl As StringDim a As Datea = DateDim D As IntegerD = Day(a)DoIf D > 10 And Me.Paid = 0 ThenStrSQl = "Insert into MsgOut (iid,msg,send,msgto) values('[GR No]','Respected Parents!Your Child Fees Has Been Due..Please Paid the dues as earliest...','Yes',Mobile);"DoCmd.RunSQL (StrSQl)End IfExit Do LoopExit HandleroCmd.SetWarnings TrueExit SubErrorHandler:MsgBox Err.Number & Chr(13) & Err.DescriptionResume ExitHandler.End Sub
    Attached Thumbnails Attached Thumbnails 33.JPG  

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Why did you get rid of the recordset? It's what you loop through to create a record for each. I would just send Emil's from the recordset, but I'm not sure what you're whole process is.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 08-22-2011, 09:02 PM
  2. Run macro on form load?
    By stu_C in forum Forms
    Replies: 3
    Last Post: 08-16-2011, 07:54 AM
  3. Form Load Check
    By Kapelluschsa in forum Forms
    Replies: 3
    Last Post: 07-06-2011, 07:21 AM
  4. Instant load of a form
    By carstenhdk in forum Forms
    Replies: 2
    Last Post: 05-06-2010, 12:27 AM
  5. On Load, form not visible
    By Bruce in forum Forms
    Replies: 15
    Last Post: 02-24-2010, 04:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums