Results 1 to 3 of 3
  1. #1
    orcinus is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Apr 2010
    Posts
    67

    Database Recognizing VBA Change to Form

    I have a database that contains code that sets the DefaultView property of a form to 'Datasheet'. Apparently in order to do this, it is required that the form be opened in Design View, so my code opens the form in Design View and sets the DefaultView Property. I then have code that closes the form and saves the settings and then re-opens the form (in normal view) so that something can be done in it.



    The problem is that when the code re-opens the form, the form opens in Single Form view. However, it appears that the code did actually change the DefaultView, because if I rem out the code that opens the form in normal view (after the design view changes) and manually open the form, the view is Datasheet.

    So, there appears to be something about opening the form manually that must somehow refresh the datatabase with the changes that opening it from code doesn't do. Is there a way in code to refresh the database so it applies the change?

    Any assistance is appreciated..here is the code:

    Public Sub mkqry_open_se_term_tbl()
    'makes a query to open the term se table so that only certain fields are displayed for user choice..
    Dim d As Database
    Dim frm As Form
    Dim qdf As QueryDef
    Dim str_sql As String
    Dim frm2 As Form

    Set frm = Forms!frm_pr_proc_sel_req
    str_sql = "select * from " & str_tbl_name_se_term
    str_qry_name_se_term = frm.cbo_assoc_id & Now()

    Set d = CurrentDb
    Set qdf = d.CreateQueryDef(str_qry_name_se_term, str_sql)

    DoCmd.OpenForm "frm_term_se", acDesign
    Set frm2 = Forms!frm_term_se
    frm2.RecordSource = str_qry_name_se_term 'set recordsource of form
    frm2.DefaultView = 2
    DoCmd.OpenForm "frm_term_se", acNormal

    DoCmd.Close acForm, "frm_term_se", acSaveYes

    DoCmd.OpenForm "frm_term_se", acNormal

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    I have a form that is single form by default.
    I use a button as follows to change to datasheet

    Private Sub Command20_Click()
    DoCmd.RunCommand acCmdDatasheetView
    Exit_Command20_Click:
    Exit Sub
    You might want to look into various options for DoCmd.RunCommand

  3. #3
    orcinus is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Apr 2010
    Posts
    67
    Quote Originally Posted by orange View Post
    I have a form that is single form by default.
    I use a button as follows to change to datasheet



    You might want to look into various options for DoCmd.RunCommand
    ok, I'll check that out..thanks..

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

Similar Threads

  1. Macro not recognizing text box value
    By avarusbrightfyre in forum Access
    Replies: 1
    Last Post: 09-17-2011, 01:45 PM
  2. DLookup not recognizing valid record/type mismatch
    By walter189 in forum Programming
    Replies: 3
    Last Post: 07-21-2011, 07:03 AM
  3. Issue recognizing Excel 'ranges'
    By Captain Database ...!! in forum Import/Export Data
    Replies: 4
    Last Post: 07-18-2011, 02:22 PM
  4. How Does One Change The Database Name
    By Garreth in forum Access
    Replies: 1
    Last Post: 04-26-2010, 04:41 PM
  5. Change database connection
    By unique in forum Access
    Replies: 1
    Last Post: 01-28-2010, 04:01 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