Results 1 to 2 of 2
  1. #1
    gammaman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    56

    front end code with user form

    I have an vba access module which when executed, creates some tables, reads excel files into those tables and then runs a bunch of queries and does some other operations. I now want to front end this with a form so that only certain portions of the code are executed based on what options on the form are seleced before a "Run" button is clicked on the form. Below is an example of my existing Module. I am just looking for an example as to how to begin front ending with form.




    Code:
    Set db = CurrentDb()    'Establish a Connection to the Current Database
    On Error Resume Next
    DoCmd.RunSQL ("Create TABLE [countPrescriptionPlan]")
    DoCmd.RunSQL ("Create TABLE [countMedicalPlan]")
    Set tb2 = db.TableDefs("countPrescriptionPlan")
    Set tb3 = db.TableDefs("countMedicalPlan")
    
    .......
    
     'Create table Definitions for Prescription Count
       countColumnsPres = Array("CountofEmplid", "CountofDepBen", "Emplid", "DepBen")
       
       For Each col In countColumnsPres
       
      ' Set field names for prescription Count
       Set FieldName = tb2.CreateField(col, dbText, 100)
       tb2.Fields.Append FieldName
       Next col
       
       'Create table Definitions for Medical Count
       countColumnsMedical = Array("CountofEmplid", "CountofDepBen", "Emplid", "DepBen")
       
       For Each col In countColumnsMedical
       
      ' Set field names for prescription Count
        Set FieldName = tb3.CreateField(col, dbText, 100)
       tb3.Fields.Append FieldName
       Next col
    
    .......
    
     DoCmd.OpenQuery "selectMedicalPlan", , acReadOnly
     DoCmd.OpenQuery "countMedPlan", , acReadOnly
     DoCmd.OpenQuery "selectPresPlan", , acReadOnly
     DoCmd.OpenQuery "countPresPlan", , acReadOnly
    
    .......
    
    
    'Insert the data returned from counrPresPlan query into a temp table
    insString = "INSERT INTO countMedicalPlan (CountofEmplid,CountofDepBen,Emplid,DepBen)" _
                     & " Select CountOfEMPLID, CountOFDEPENDENT_BENEF1, EMPLID, DEPENDENT_BENEF" _
                      & " From countMedPlan"
                      
    DoCmd.RunSQL insString
    
    'Insert the data returned from counrPresPlan query into a temp table
    insString2 = "INSERT INTO countPrescriptionPlan (CountofEmplid,CountofDepBen,Emplid,DepBen)" _
                      & " Select CountOfEMPLID, CountOFDEPENDENT_BENEF1, EMPLID, DEPENDENT_BENEF" _
                      & " From countPresPlan"
                      
    
    ..........

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    If you want code to be conditional then use If Then Else or Select Case structures.

    Whether the code is in general module or behind form determines how you refer to the form controls.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 7
    Last Post: 03-13-2013, 07:34 PM
  2. Replies: 4
    Last Post: 01-09-2013, 05:26 PM
  3. Replies: 1
    Last Post: 11-16-2012, 10:25 AM
  4. Replies: 1
    Last Post: 11-13-2012, 02:27 PM
  5. Access front end hangs when more than one user
    By mafrank101 in forum Access
    Replies: 3
    Last Post: 05-31-2012, 10:15 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