Solved

Refreshing the dtaagrid and related controls

Posted on 2000-03-19
3
159 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now