[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Open Form from vba module

Posted on 2004-03-21
3
Medium Priority
?
850 Views
Last Modified: 2008-02-01
Hi

I have a switchboard (form) with a project name and number that is stored in a table (project_info).

The switchboard is the first form that opens (set in the startup options menu).

I have a form for users to enter the project name and number (called Project_details). This only needs to be entered once for the life of the database (until it is used for a new project).

If there is no project name or number in the table then the code that fetches the number onto the form comes up with an error because there is no recordset in the empty project_info table.

I want to either:-

a) open the project_details form on the first time to get the users to fill in the form, before the switchboard comes up. But I can't see how to programatically change startup options without having opened the database once already.

b) get the vb function I have written to get the name and number on the switchboard to open the form if there are no records in the table. I have tried using the
DoCmd.OpenForm ("Project_details") in my vb function.

This works if the procedure is run from the vb module but when I try to run it by opening the switchboard (which calls the getProjNumber function via a text box) I get the message "You can't carry out this action at the present time" and the debugger highlights the DoCmd line.

Does anyone have any ideas or do I have to just resign myself to the fact that I'm trying the impossible?!

Here is my function (in the modules section)
Function GetProjectName()

    Dim rstName As ADODB.Recordset
           
    Set rstName = New ADODB.Recordset
        rstName.Open "Project_details", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
       

    If (rstName.BOF = True) Or (rstName.EOF = True) Then
        rstName.Close
   
        DoCmd.OpenForm "Project_details"
   
   Else
    GetProjectName = rstName!Project_name
    rstName.Close
   End If
     
End Function
0
Comment
Question by:willmottj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 14

Accepted Solution

by:
bluelizard earned 1000 total points
ID: 10646971
i'd do the following:

in the original database (i.e., in the version that the users initially opens), make the project_details form the startup form.  in that form, when the users clicks OK, programmatically modify the startup form...:

  Dim wdb As Database
  Set wdb = CurrentDb
  wdb.Properties("StartupForm") = “MySwitchboardForm”
  Set wdb = Nothing

...and go to the switchboard:

  DoCmd.OpenForm “MySwitchboardForm”
  DoCmd.Close acForm, “project_details”, acSaveNo


(note: the above code to change the properties requires the DAO object library; if necessary, install it with "Tools > References" from a VB window)


--bluelizard
0
 
LVL 1

Expert Comment

by:ajysen
ID: 10649085
you can do the following, insert the below code in the Vb module and set the Project properties --> Startup Object to Sub Main.

Public Sub main()
     Open your connection here
    call GetProjectName
End Sub

by doing so u have set the startup object to Sub main, where u are opening ur connection, once ur connection is open u can manipulate ur code depending upon ur needs.This will work.
0
 

Author Comment

by:willmottj
ID: 10653333
Thanks bluelizard. This solution actually dawned on me whilst discussing this problem with a friend after work yesterday. But it's good to see what the code will look like.

Thanks
willmottj
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question