Page 2 of 2 FirstFirst 12
Results 16 to 27 of 27
  1. #16
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    you need the same code in the cbxWorkmonth before update control

  2. #17
    cindyLiu is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2014
    Posts
    48
    Hello All,

    I still have a question for the code, could you take a look #15?

    Thanks,
    Cindy

  3. #18
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    every time you try to leave the cbxschoolName control, you will trigger the cbxschoolName beforeupdate event. Suspect you also need an cbxschoolName.undo to go with your cancel=true so the beforeupdate event is not triggered

  4. #19
    cindyLiu is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2014
    Posts
    48
    Thanks. But it didn't work. it didn't allow me to do anything when I click the WorkMonth combo box and always pop-up the same error message which I put in the code.

    Thanks,
    Cindy

  5. #20
    cindyLiu is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2014
    Posts
    48
    Thank you so much, Ajax! I follow your #16 and #18, and the code is working!!!!!!!!!!!!
    Cindy

  6. #21
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    regret I don't have time to play around with different scenarios. Suggest comment out the 'Cancel=true' line

    Ahh- see my original suggestions have worked

  7. #22
    cindyLiu is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2014
    Posts
    48
    Thanks, you are great!
    Cindy

  8. #23
    cindyLiu is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2014
    Posts
    48
    Got a syntax error when I selected a school, name likes this "xxxxx's elementray school", could you tell how to fix it?

    If DCount("*", "TBL_DataEntry", "WorkMonth='" & Me.cbxWorkMonth & "' AND SchoolName='" & Me.cbxschoolName & "'") > 0 Then

    Thanks,
    Cindy

  9. #24
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    you need to use the replace function to replace the single quote with two single quotes


    ....AND SchoolName='" & replace(Me.cbxschoolName,"'","''") & "'")....

  10. #25
    cindyLiu is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2014
    Posts
    48
    Thanks, I changed the code for Private Sub cbxSchoolName_BeforeUpdate(Cancel As Integer), and when I selected a schools, then it works.
    then, I thought I should also changed the code for Private Sub cbxWorkMonth_BeforeUpdate(Cancel As Integer), but I got an error when I tried to select a month first : "Run-time error '94', Invalid use of null".

    Private Sub cbxWorkMonth_BeforeUpdate(Cancel As Integer)
    If DCount("*", "TBL_DataEntry", "WorkMonth='" & Me.cbxWorkMonth & "' AND SchoolName='" & Replace(Me.cbxschoolName, "'", "''") & "'") > 0 Then
    cbxWorkMonth.Undo
    Cancel = True
    MsgBox "Sorry, you already have a report for this school in this month"
    End If
    End Sub

    Private Sub cbxSchoolName_BeforeUpdate(Cancel As Integer)
    If DCount("*", "TBL_DataEntry", "WorkMonth='" & Me.cbxWorkMonth & "' AND SchoolName='" & Replace(Me.cbxschoolName, "'", "''") & "'") > 0 Then
    cbxschoolName.Undo
    Cancel = True
    MsgBox "Sorry, you already have a report for this school in this month"
    End If
    End Sub

  11. #26
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    sounds like yo do not have a value for schoolname - you need to use the nz function

    Replace(nz(Me.cbxschoolName,""), "'", "''")

  12. #27
    cindyLiu is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2014
    Posts
    48
    Thank you so much, Ajax. SUPER!
    Cindy

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. check if column exist
    By xopherira in forum Modules
    Replies: 5
    Last Post: 08-25-2015, 02:09 PM
  2. Check if record exist
    By sahand in forum Forms
    Replies: 2
    Last Post: 06-11-2014, 07:07 AM
  3. Replies: 9
    Last Post: 08-15-2013, 04:28 PM
  4. If exist update else enter
    By mkling in forum Access
    Replies: 15
    Last Post: 05-22-2012, 07:44 AM
  5. Check if value exist in a table
    By Lucas83 in forum Programming
    Replies: 2
    Last Post: 06-02-2010, 11:42 AM

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