?
Solved

Database Fields

Posted on 2003-03-24
12
Medium Priority
?
169 Views
Last Modified: 2013-11-20
I have made a program using MFC that displays an access database (using DAO).

I am now just making it easier to use, and can only scroll through the records using the toolbar that was automatically put at the top of the program (First, Last, Next, Previous).

I want to add my own buttons that allow me to browse thru the records, what code do i need to use to do this?

Ive been looking around and have found some code i put into my OnButton() :-

m_pSet.MoveNext();

but i get an error :-

error C2228: left of '.MoveNext' must have class/struct/union type

Any help is appreciated !!
0
Comment
Question by:ChrisWUK
[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
  • 6
  • 6
12 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 60 total points
ID: 8194627
1) Include appropriate h-file (something like MySet.h) - CDaoRecordset-derived class created by Wizard
2) Change:
m_pSet->MoveNext();

(m_pSet is pointer)
0
 

Author Comment

by:ChrisWUK
ID: 8194905
didnt need to add a header, just changed the . to a ->

Thanks mate, just 1 more thing :-

When i'm at the 1st record, i need Previous to be disabled and the same with when i'm on the last record, i need the next button to be disabled.

Ive found that IsBOF Returns TRUE if the current record is the first record in the set, and, IsEOF Returns TRUE if the current record is the last record in the set.

How would i implement this into my code, it doesnt seem to recognice the IsBOF or IsEOF commands
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 8195090
Using MFC Class Wizard, add WM_COMMAND_UI message handlers for all recordset commands (ID_RECORD_FIRST ...). Message handlers look like this:

void CSample1View::OnUpdateRecordFirst(CCmdUI* pCmdUI)
{
    pCmdUI->Enable(...);    
}

Write logical expression inside of Enable call using m_pSet variable. For example:


pCmdUI->Enable( m_pSet && (! m_pSet->IsBOF()));

This line disables ID_RECORD_FIRST command if IsBOF returns TRUE.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ChrisWUK
ID: 8195324
is there any easier way to do this?

Cant the next button just be disabled when the last record is shown and vice versa?
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 8195521
The dialog button can be disabled explicitly using EnableWindow function. But menu item and toolbox button can be enabled/disabled/checked/unchecked only using WM_COMMAND_UI message handler (in MFC SDI/MDI application). If you try to disable toolbox button out of WM_COMMAND_UI handler, this has no effect.

WM_COMMAND_UI is easy way. All you need is to write the condition when the command should be enabled/disabled. MFC Framework applies it when necessary.
0
 

Author Comment

by:ChrisWUK
ID: 8195562
any chance of explaining it step by step and where to go, cos im a little lost with what you said b4, thanks for the help  :)
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 8195658
Right-click on your View class, select "Add Message Handler". Select one of Move commande (for example, ID_RECORD_FIRST), double-click on WM_COMMAND_UI. Press OK. Edit function text. Run the program and see the result - Move First button is disabled when you are in the beginning of recordset.
0
 

Author Comment

by:ChrisWUK
ID: 8195763
ok - done that and added the code :-

void CENGCWARE2View::OnUpdateRecordFirst(CCmdUI* pCmdUI)
{
pCmdUI->Enable( m_pSet && (! m_pSet->IsBOF()));    
}

But on the first record, the previous button is still enabled and if clicked, produces an error message (as there is no recoed before the 1st)
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 8195852
That means IsBOF returns TRUE only when current record is out of range (and not first). You know how to enable/disable buttons, just find another expression instead of IsBOF. For example, you can keep current recordset position in class member and disable button if it is <=1.
Remember that OnUpdate... function should be fast because it is called in application idle time.
0
 

Author Comment

by:ChrisWUK
ID: 8196011
How do u disable the button?

m_button.enable = false?

By the way, thanks for ur help today
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 8200662
m_button.EnableWindow(FALSE);
0
 

Author Comment

by:ChrisWUK
ID: 8202370
Thanks for all your help me - u really helped me out there !

Ive become an expert now thanks to you and will gladly help out any1 else when i can  :)
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Suggested Courses

777 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