dcsimg
Results 1 to 7 of 7

Thread: if.. to query as rowsource

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    103

    if.. to query as rowsource

    hello guys.
    i m using MSaccess to build a database.
    the acess consists of a main form and a subform.

    i need to specify the rowsource(a query) of a field in the subfrom based on the value of a field on a main form in VB code.
    the thing is that i m not able to reference to the query to make it a rowsource in VB code.

    can anybody help and thx

    like

    if form_mainform.field.value="xxx" then form_subform.field1.rowsource=??(query reference).

  2. #2
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: if.. to query as rowsource

    Well an easy and quick solution, since it looks like you're searching for a particular record with this, is to go to the query you are using as your subform and open it in design mode.

    Then, find the field in your query that corresponds to the field on your form, like "FullName". Under criteria, type [Tempvars]![FullName].

    Then write a quick macro to CreateTempVar, make sure that the name of your tempvar is "FullName" and the source is [yourform]![yourfield].

    In your form, use the AfterUpdate event for your field and use this

    Code:
    DoCmd.RunMacro "YourMacro"
              form_subform.Requery

  3. #3
    New Member
    Join Date
    Oct 2007
    Posts
    2

    Re: if.. to query as rowsource

    hiii

    i am using VB 6.0. It does not show 'database' as a keyword, it gives

    Compiler Error: User-defined type not defined.

    In all d example codes, 'database' is assumed to be a keyword.
    Is the problem with the installation of VB? The VB that I have installed does not have MSDN collection. Should I try reinstalling VB??

  4. #4
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: if.. to query as rowsource

    Smitas,
    you need to add a reference of your required database object to your project.
    What database you are using and what is the technology you want to use...
    If DAO then select Microsoft DAO 3.51 Object Library from Project Menu -> References submenu.
    Or if you want to use ADO then select Microsoft Activex Data Objects x.x Library
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  5. #5
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: if.. to query as rowsource

    is that really necessary though? If you are using DAO then what about the expression
    Code:
    Set database = CurrentDb()

  6. #6
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,350

    Re: if.. to query as rowsource

    At this point if you ate using VB6 to write the app I would not l=even think of using DAO use ADO. DAO was out of date in about 1997
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  7. #7
    New Member
    Join Date
    Oct 2007
    Posts
    2

    Re: if.. to query as rowsource

    Quote Originally Posted by ganeshmoorthy
    Smitas,
    you need to add a reference of your required database object to your project.
    What database you are using and what is the technology you want to use...
    If DAO then select Microsoft DAO 3.51 Object Library from Project Menu -> References submenu.
    Or if you want to use ADO then select Microsoft Activex Data Objects x.x Library

    Thanks a lot for the info.
    I have never worked with VB database connections before.
    I have 2 make a management system for a local trust. Is using MS Access fine, or is there a better way to connect to ?
    Can u tell me wat is DSN & how it is related ?

    Set db = ws.OpenDatabase("", False, False, strConnection)
    What does this line do?

    Thanks.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width