Results 1 to 6 of 6

Thread: VBA Recordset / Parameters

  1. #1
    Join Date
    Dec 2009
    Posts
    296

    VBA Recordset / Parameters

    Hello,
    Here I would like to use data from a query parameter as a date that the person entered on a form. I am dealing with the recordset and parameters.
    Here's the code:
    Code:
    Private Sub BT_GEN_CONSTAT_Click()
     
    Sun qdf As DAO.QueryDef
    Sun rcs As DAO.Recordset
    Sun strLigneText As String
    Sun strConstante As String
    Sun schm As String
    Sun infr As Integer
    Sun db As DAO.Database
    
    infr = FreeFile()
        schm = "C: \ test.txt"
        Open schm For Output As # infr
    
    
    Set db = CurrentDb()
    Set qdf = db.QueryDefs("para_const")
    qdf.Parameters("Forms! F_GEN_CONSTAT! DATE_CONSTAT") = Forms! F_GEN_CONSTAT![DATE_CONSTAT]
    Set rcs = qdf.OpenRecordset
    ...
    When I try to run the following code , i get an error, do you have any idea about the error and please let me know why my code is giving an error.

  2. #2
    Join Date
    Nov 2009
    Posts
    333

    Re: VBA Recordset / Parameters

    Hello,
    In the VBA it should be used Forms instead of the one which you have used in your code. Please check the following.
    Code:
    qdf.Parameters("Forms! F_GEN_CONSTAT! DATE_CONSTAT") = Forms! F_GEN_CONSTAT![DATE_CONSTAT]
    Hope the following correction will help you. If you have any more queries regarding this then please post back and we will try to solve your queries.

  3. #3
    Join Date
    Dec 2009
    Posts
    178

    Re: VBA Recordset / Parameters

    Hello,
    Even I am trying a similar kind of a code and I have done some coding part also. I still have the same problem using "Forms"! In the above post you said to correct the usage of the Form, even when correcting the code I am getting the same error, because i had done the same mistake that you had done. At the request must he said parameters in "query parameters? If this can be done then please let be know , How? And any more information on this is appreciated.

  4. #4
    Join Date
    Dec 2009
    Posts
    296

    Re: VBA Recordset / Parameters

    Hello,
    Here is my modified code, please have a look at it
    Code:
    Private Sub BT_GEN_CONSTAT_Click()
     
    Sun qdf As DAO.QueryDef
    Sun rcs As DAO.Recordset
    Sun strLigneText As String
    Sun strConstante As String
    Sun schm As String
    Sun infr As Integer
    Sun db As DAO.Database
    
    infr = FreeFile()
    schm = "C: \ test.txt"
    Open schm For Output As # infr
    
    
    Set db = CurrentDb()
    Set qdf = db.QueryDefs("R_PREPA_CONSTAT")
    qdf.Parameters("Forms! F_GEN_CONSTAT! DATE_CONSTAT") = Forms! F_GEN_CONSTAT![DATE_CONSTAT]
    Set rcs = qdf.OpenRecordset
    ...

  5. #5
    Join Date
    Nov 2009
    Posts
    347

    Re: VBA Recordset / Parameters

    Hello,
    It is not mandatory but is better. Especially because it allows "typing" parameter. In the column "Parameter" You know the name of the parameter you wish to use later in your application. It is not useful to, as a parameter name, an expression based on a form (like what you use). In the column "Type", you choose the type of data. Then a stroke continued it. Then, still in your query displayed in design mode, you use your argument, such a criterion. Hope this information will help you.

  6. #6
    Join Date
    Nov 2009
    Posts
    359

    Re: VBA Recordset / Parameters

    Hello,
    I have a small code with me, I think you it will help you.
    Here is the part of the code
    Code:
    Set db = CurrentDb()
    Set q = db.QueryDefs("R_PREPA_CONSTAT")
    q.Parameters("MonPara") = Forms! F_GEN_CONSTAT![DATE_CONSTAT]
    Set rs = q.OpenRecordset
    Try the above code in your program and see if it works and if not then post back with the error you are getting.

Similar Threads

  1. Turning a Recordset into table
    By Windowed in forum Windows Software
    Replies: 5
    Last Post: 28-12-2009, 03:04 PM
  2. How to return a recordset from a function in ASP
    By Ananias in forum Software Development
    Replies: 3
    Last Post: 19-06-2009, 11:35 PM
  3. BIOS parameters
    By bayz in forum Overclocking & Computer Modification
    Replies: 4
    Last Post: 01-01-2009, 10:48 PM
  4. SATA no parameters
    By super soaker in forum Hardware Peripherals
    Replies: 4
    Last Post: 01-12-2008, 06:18 PM
  5. Ms Access throws "This recordset is not updateable. "
    By Landon in forum MS Office Support
    Replies: 1
    Last Post: 22-11-2006, 04:12 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,020,764.36017 seconds with 17 queries