• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

Database Fields

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
ChrisWUK
Asked:
ChrisWUK
  • 6
  • 6
1 Solution
 
AlexFMCommented:
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
 
ChrisWUKAuthor Commented:
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
 
AlexFMCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
ChrisWUKAuthor Commented:
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
 
AlexFMCommented:
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
 
ChrisWUKAuthor Commented:
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
 
AlexFMCommented:
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
 
ChrisWUKAuthor Commented:
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
 
AlexFMCommented:
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
 
ChrisWUKAuthor Commented:
How do u disable the button?

m_button.enable = false?

By the way, thanks for ur help today
0
 
AlexFMCommented:
m_button.EnableWindow(FALSE);
0
 
ChrisWUKAuthor Commented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now