Results 1 to 5 of 5
  1. #1
    scoe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2013
    Posts
    91

    VBA Code

    I have an error in code set up in one of our databases and I can't see why it doesn't like it. Any help would be gratefully appreciated.



    Code:
    Private Sub Course_GotFocus()
       Dim Msg, Style, Title, Help, Ctxt, Response, MyString
       If ClaimCount > 0 Then
          Msg = "Would you like to print the claim form before you select another course? If you don't, the claims for this course will be lost"
          Style = vbQuestion + vbYesNo
          Title = "Change course?"
          Response = MsgBox(Msg, Style, Title, Help, Ctxt)
          If Response = vbYes Then         If TotalEnglish > 0 And TotalNotEnglish = 0 Then
                stDocName = "Functional Skills Entry Level ENGLISH"
                DoCmd.OpenReport stDocName, acPreview
             Else
                If TotalEnglish > 0 And TotalNotEnglish > 0 Then
                   stDocName = "Functional Skills Entry Level plus ENGLISH"
                   DoCmd.OpenReport stDocName, acPreview
                Else
                   stDocName = "Functional Skills Entry Level"
                   DoCmd.OpenReport stDocName, acPreview
                End If
             End If
             DoCmd.SetWarnings False
             stDocName = "Update FS Entry Level Claims"
             DoCmd.OpenQuery stDocName, acNormal, acEdit
             Refresh
             stDocName = "Update FS Entry Level Claims ENGLISH"
             DoCmd.OpenQuery stDocName, acNormal, acEdit
             Refresh
          End If
          Forms![Functional Skills Entry Level].Requery
          If Response = vbNo Then
             stDocName = "Clear Functional Skills Entry Level Claims"
             DoCmd.OpenQuery stDocName, acNormal, acEdit (This is the bit the debug selected)
             Course.SetFocus
          End If
       End If
    Exit_Course_GotFocus_Click:
       Exit Sub
    End Sub
    Last edited by RuralGuy; 06-20-2013 at 03:40 PM. Reason: Added code tags and indenting

  2. #2
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    FYI - if you put the word CODE in square brackets [] before your code, and /CODE in square brackets afterward, then the forum will preserve your indenting, making it easier to read.


    I don't see anything much wrong with it, syntax-wise.
    First, verify that this is actually the precise name of a query: "Clear Functional Skills Entry Level Claims"

    Code Cleanup -

    1) It may help identify some problems if, at the top of the module, you put :
    Option Compare Database
    Option Explicit

    2) Next, declare all your variables

    Dim stDocName As String
    Dim stQueryName As String

    3) For the DoCmd OpenQuery, use stQueryName instead of stDocName (this is for clarity, not for syntax)

    4) For the DoCmd OpenQuery, use acViewNormal rather than acNormal. Both those constants equate to zero, so that's not your problem. Once again, this is for clarity, not syntax.

  3. #3
    scoe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2013
    Posts
    91
    Thank you, I will have another look at it.

  4. #4
    scoe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2013
    Posts
    91
    Thank you , just to update, I went back to the original data and broke it down to two select queries and then combined them to get the correct answer in the end, thank you again for all your help.

  5. #5
    scoe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2013
    Posts
    91
    Thank you, my error (mispelled the check box) works brilliantly

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

Similar Threads

  1. Report Code is not allowing return to main code
    By rcwiley in forum Programming
    Replies: 2
    Last Post: 06-16-2013, 10:31 AM
  2. Replies: 7
    Last Post: 05-28-2013, 09:11 AM
  3. Replies: 1
    Last Post: 05-04-2013, 12:19 PM
  4. Word code in Access - How to modify my current code
    By Alexandre Cote in forum Programming
    Replies: 0
    Last Post: 11-15-2010, 08:26 AM
  5. Code in combobox, code in text box
    By float in forum Forms
    Replies: 3
    Last Post: 09-29-2010, 07:12 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