Results 1 to 4 of 4
  1. #1
    Tman is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2010
    Posts
    7

    Skip Option on form - how to auto update all questions with VBA

    Hi all

    I want to include an option on a survey form which will be a "Skip" button. Basically when the user selects this, I want the code to insert assigned values (responses) for questions that were on the form.

    The survey contains 6 sections (each with a separate form). Within each "Section", there are 10 questions. A couple sections are optional, so if the user selects skip, that section closes, next one opens.

    I know this is wrong below (although some parts work). The parts that work are the QuestionChoice value and long response values entered into the table. The part that doesn't work is the SurveyQuestionID part (it only updates for the current question, not for all questions in that section). The example below I have the SurveyQuestion value assigned as the current question on the form.

    I don't know how to program it so that it auto inserts the assigned values for ALL questions in that section? I am thinking it needs the "SectionID" in there somewhere also, so the code can identify what questions are assigned to that section, and insert the assigned values for every question in that section?

    appreciate any help, hopefully explained it well enough above!

    Thanks
    TB

    Private Sub cmdSkip_Click()

    Dim SurveyQuestionID
    Dim QuestionChoiceID
    Dim LongResponse

    SurveyQuestionID = Me.SurveyQuestionID
    QuestionChoiceID = 0


    LongResponse = "No Additional Comments provided by assessor."

    Dim strSQL As String
    strSQL = "INSERT INTO tblTEMPSurveyLongResponse (SurveyQuestionID, QuestionChoiceID,LongResponse) "
    strSQL = strSQL & "VALUES "
    strSQL = strSQL & "(" & SurveyQuestionID & ", " & QuestionChoiceID & ", '" & Replace(LongResponse, "'", """") & "')"

    DoCmd.SetWarnings False
    DoCmd.RunSQL strSQL
    DoCmd.SetWarnings True
    Me.txtComments = ""


    DoCmd.Close


    End Sub

  2. #2
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    Probably the easiest way would be to add a field to your Table that shows the section the question belongs to. Then, when someone chooses "Skip" you can run a Query "WHERE SectionID=currentSection"

    That would update every question in the section.

  3. #3
    Tman is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2010
    Posts
    7
    Quote Originally Posted by Rawb View Post
    Probably the easiest way would be to add a field to your Table that shows the section the question belongs to. Then, when someone chooses "Skip" you can run a Query "WHERE SectionID=currentSection"

    That would update every question in the section.
    yeah thanks Rawb. I do already have that, but i just am unsure of how to code that into the SQL, to insert to all questions in that section, namely assigning that value to;

    SurveyQuestionID = Me.SurveyQuestionID

    SurveyQuestionID = All questions where SectionID = etc

  4. #4
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    Unfortunately I'm not good enough with SQL statements to resolve your issue using your existing code. It's not that using DoCmd.RunSQL won't work or that it's the "wrong" way to do what you want, it's just not how I'd do it.

    I prefer to do things programmatically rather than through SQL.

    That said, I'd be happy to take a look at your code and see if I can do it my way. If you're not that familiar with VBA though, it might not be as easy to update.

    However, I did notice that you're using a temporary Table to store the answers in. Have you considered pre-populating the Table with all the questions at the start of the survey? Then, as the user answers them, you can just run Update Queries. It would also likely solve your problem since you could just run the following Query when the user decides to skip an entire section:

    Code:
    strSQL = "UPDATE tblTEMPSurveyLongResponse SET LongResponse='" & _
             LongResponse & "' WHERE SurveySectionID=" & SurveySectionID
    
    DoCmd.RunSQL strSQL
    This is assuming that SurveySectionID contains the value you've assigned to this section (and that your sections are identified by numbers, not by text).

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

Similar Threads

  1. Replies: 3
    Last Post: 04-14-2010, 10:07 AM
  2. Auto Update Forms
    By Vikki in forum Forms
    Replies: 1
    Last Post: 02-09-2010, 10:51 AM
  3. no option to import xls file or option all files
    By captgnvr in forum Import/Export Data
    Replies: 3
    Last Post: 09-22-2009, 10:19 AM
  4. auto update of two linked tables
    By colenzo in forum Access
    Replies: 4
    Last Post: 07-20-2009, 09:08 AM
  5. Replies: 1
    Last Post: 03-08-2009, 01:50 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