Results 1 to 15 of 15
  1. #1
    Grooz13 is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Aug 2010
    Posts
    97

    Unhappy Code about a check box to change value in tables crash my access

    I have a form i created to work like a calendar and I have listbox so i can drag and drop jobs on the day i want the job to be done and it works well and it changes the date in my database... however I would like my client to be sent a new fax telling him we changed the date of the job... I added a checkbox on my Form and if the checkbox is checked it will change the value fax (a yes/no field) to no so my secretary will resend a fax to everyone with changed date at the end of t he day...



    however... the code is crashing my access every single time... if I don't go step by step in the code... it simply close... no message nothing... If I don't go step by step it's simply crash access, no answer from access at all ... he is my code

    Code:
     
    Dim DateF As Date
    Dim LeSQL As String
    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    DateF = DateDebut + ind2 - 1
    Set db = CurrentDb
    LeSQL = "Select Date_Shipping, Fax from Tbl_Production where No_Job_Auto=" & NC
    Set rst = db.OpenRecordset(LeSQL, dbOpenDynaset)
     If Not rst.EOF Then
        rst.Edit
        rst!Date_Shipping_Debut = DateF
       If Btn_Fax= True Then
       rst!Fax = -1
       End If
        rst.Update
     End If
    rst.Close
    Set rst = Nothing
    db.Close
    Set db = Nothing
    what's in bold is my new code... if i remove it, it works flawlessly anyone have an idea ? (p.s sorry for my really bad english it's not my first language)

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Try removing the test and just setting the field value as a test:
    Code:
    '-- If Btn_Fax= True Then
       rst!Fax = -1
    '-- End If

  3. #3
    Grooz13 is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Aug 2010
    Posts
    97
    what do you mean 6

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    See if just trying to change the field will kill Access.

  5. #5
    Grooz13 is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Aug 2010
    Posts
    97
    no it don't crashed it

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    So it looks like this line:
    Code:
    If Btn_Fax= True Then
    ...is the line that crashes the system. Try typing it over again and leave the old line commented out. Does it still crash?

  7. #7
    Grooz13 is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Aug 2010
    Posts
    97
    yeah it still crash :S

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Try:
    Code:
    If Me.Btn_Fax = True Then

  9. #9
    Grooz13 is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Aug 2010
    Posts
    97
    it still crash again... i'm so hopeless

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Is your system up to date with patches? Both Win7 and Access 2007? Have you done a Compact and Repair?

  11. #11
    Grooz13 is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Aug 2010
    Posts
    97
    yeah system is up to date and I did compact and repair, it's in a fonction... does it has anything to do with this ?

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Sometimes just a section of code can be corrupt, especially if you edit the code while the debugger is running. Maybe try importing your system into a fresh db.

  13. #13
    Grooz13 is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Aug 2010
    Posts
    97
    It's really weird.. this if crash my access wherever I put him... I tried changing my control to put a radio button but it crashed again... what is wrong with me

  14. #14
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Like I said, IMPORT your db into a new empty db. I suspect your db is corrupt and importing into a new db might cure it.

  15. #15
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    Is the function an Event in your Form? Or is it in a Module?

    If it's in a Module, you need to either reference the Check Box using the full path to the Form or pass it to the Function as a variable:

    Code:
    Dim DateF As Date
    Dim LeSQL As String
    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    DateF = DateDebut + ind2 - 1
    Set db = CurrentDb
    LeSQL = "Select Date_Shipping, Fax from Tbl_Production where No_Job_Auto=" & NC
    Set rst = db.OpenRecordset(LeSQL, dbOpenDynaset)
     If Not rst.EOF Then
        rst.Edit
        rst!Date_Shipping_Debut = DateF
       If [Forms]![MyForm]![Btn_Fax]= True Then
       rst!Fax = -1
       End If
        rst.Update
     End If
    rst.Close
    Set rst = Nothing
    db.Close
    Set db = Nothing
    Be sure to change MyForm to the Form's name.

    Also, if Tbl_Production.Fax is a Yes/No Field, you should set it to False instead of -1. Setting a non-number Field to a number can sometimes cause strange things to happen.

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

Similar Threads

  1. how to change report code page
    By broken_ice in forum Reports
    Replies: 1
    Last Post: 06-27-2010, 02:23 AM
  2. Code to spell out check amount?
    By spkoest in forum Access
    Replies: 4
    Last Post: 06-16-2009, 07:44 PM
  3. Replies: 4
    Last Post: 05-12-2009, 01:50 PM
  4. Replies: 1
    Last Post: 08-10-2008, 01:09 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