Results 1 to 8 of 8

Thread: Calling From from recordset

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 1999
    Location
    Chester, NJ, Morris
    Posts
    12

    Post

    Greetings,

    I a have an Access database where I store all my forms by FormName along with a description. These forms are all part of the same project. What I would like to do is be able to select the form description from a DbGrid and have that form displayed. From the recordset I can place the name in a string var but that is as far as I get. Help! how can I go from var to screen?

  2. #2

    Thread Starter
    New Member
    Join Date
    Jul 1999
    Location
    Chester, NJ, Morris
    Posts
    12

    Post

    Thats Calling FORM from Recordset - it's early...

  3. #3
    Lively Member
    Join Date
    Jun 1999
    Location
    Raleigh, NC
    Posts
    70

    Post

    You need to create a routine that will go thru the all the forms in your app, checking each form to see if its name is equal to the name ( or description) of the form you selected from the grid. You can't use the Forms collections, since this only looks at forms that are currently open... instead you have to use Containers.... Something like this

    For i = 0 to CurrentDb.Containers(1).Documents.Count -1
    if (grdSelection) = CurrentDb.Containers(1).Documents(i).Properties(8).Value then
    'you have found the right form description
    DoCmd.OpenForm CurrentDb.Containers(1).Documents(i).Name
    End If
    Next i

    Bash

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 1999
    Location
    Chester, NJ, Morris
    Posts
    12

    Post

    Bashfirst,

    Thanks for the reply, however I am not using Access form objects. I am using forms developed in VB. The names and descriptions of these forms are stored in an Access database as text. I need to take the text apply it to a variable and say variable.show (which doesn't work). This is what I have so far:

    Data2.RecordSource = "Select NameofForm from Menu_Mstr where MenuID = " & Data1.Recordset!MenuID
    Data2.Refresh

    Dim sform As String
    sform = Data2.Recordset!NameofForm

    What next?

  5. #5
    Lively Member
    Join Date
    Mar 1999
    Posts
    93

    Post

    Next try this:

    Call OpenForm sForm
    Sub OpenForm(sName as string)
    Dim f as Form
    For each f in Forms
    if f.Name = sName then
    f.open
    exit for
    End if
    next
    End sub

    ------------------
    Regards,
    Vit

    [This message has been edited by Vit (edited 08-25-1999).]

  6. #6
    Lively Member
    Join Date
    Jun 1999
    Location
    Raleigh, NC
    Posts
    70

    Post

    Actually, Vit's solution has the same problem... the Forms collection only references the open forms, so your application would have to load all your forms for that to work.... then you could show them when appropriate. This is probably not the best way to go.... the alternative would be to create a procedure which takes the name of the form as a string, goes thru a Select Case and opens the appropriate form... This solution isn't as pretty but it would work.

    Public Sub OpenFormByName (sFormName as String)
    Select Case sFormName
    Case "frmMain"
    frmMain.Show
    Case "frmDetail"
    frmDetail.Show
    Case Else
    MsgBox "Oops"
    End Select

    Hope this helps.
    Bash

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 1999
    Location
    Chester, NJ, Morris
    Posts
    12

    Post

    bashfist,

    You are right about Vit's solution. My goal is to try not to hard code the form names as in the Select case method, but I do not think I have a choice.

    Anyway, thanks to the both of you.

    Pmeredith

  8. #8
    Lively Member
    Join Date
    Jun 1999
    Location
    Raleigh, NC
    Posts
    70

    Post

    One last thought (as if we haven't already beat this one down)...

    In essence you are trying to late bind a form. Since we can't do that, what about using a DLL to display each form. Those you _can_ late bind using the users selection from the recordset. This would avoid having o hard code the form names.

    Bash

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width