Solved

Refreshing the dtaagrid and related controls

Posted on 2000-03-19
3
164 Views
Last Modified: 2012-05-04
In this small snip of code, I am trying to clear the current recordsource,recordsets of the data control and the data grid. And I want to be able to reset them as something else, when chosen by the iser. I hope this makes some sense. How do I go about doing this?

------------------------------------------------------


 'reset/clears datagrid before conducting search
    Set grdDataGrid.DataSource = Nothing
   
    'grdDataGrid.ReBind             do I need this?
    grdDataGrid.Refresh
       
    'closes recordset to close the previous query/datasource
    If datPrimaryRS.Recordset.State = adStateOpen Then
        datPrimaryRS.Recordset.Close
    End If
    datPrimaryRS.RecordSource = ""
   
    'resets the query building string
    sSQL = ""       'query variable
    qFlag = 0       'query flag
   
               
    'starts the search
    'creates new recordset to be used as search string(query)
    If datPrimaryRS.Recordset.State = adStateClose Then
        datPrimaryRS.Recordset.Open
        datPrimaryRS.Recordset.Requery
    End If
   
    Command4.Visible = True     'shows print button
0
Comment
Question by:slimbx
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
Voodooman earned 25 total points
ID: 2635452
Hi!

You dont really need most of this.

You dont need to close rec sets etc.

'Just get the SQLstring and set it as 'the record source

datPrimaryRS.RecordSource = Sqlstring
datPrimaryRs.Refresh

'Tell the user if no records found
'**********************************
'the datagrid will be empty
'****************************
if rsPrimaryrs.recordset.recordcount=0 then
msgbox "No records found matching your criteria"

'Record sets automatically close when you close the form bound grids automatically refresh - you can rebind if you have a problem
'******************

Good Luck
Voodooman!

 
     
   
0
 

Author Comment

by:slimbx
ID: 2636585
Thanks much Voodooman.

slimbx
0
 
LVL 5

Expert Comment

by:Voodooman
ID: 2636925
Thanks for the points.

There are lots of people on the site who refuse to give points for good answers (because they are saving them). This is unfair and puts people off answering - I answer for the buzz of getting the points - if i dont get points its a waste of time.

Good luck with your VB.

Remember in General terms all objects close when you close a form - no need to close them.

Voodoman
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

837 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