Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Refreshing the dtaagrid and related controls

Posted on 2000-03-19
3
Medium Priority
?
171 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
Voodooman earned 100 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

597 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