ChrisWUK
asked on
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 !!
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 !!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Using MFC Class Wizard, add WM_COMMAND_UI message handlers for all recordset commands (ID_RECORD_FIRST ...). Message handlers look like this:
void CSample1View::OnUpdateReco rdFirst(CC mdUI* 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.
void CSample1View::OnUpdateReco
{
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.
ASKER
is there any easier way to do this?
Cant the next button just be disabled when the last record is shown and vice versa?
Cant the next button just be disabled when the last record is shown and vice versa?
The dialog button can be disabled explicitly using EnableWindow function. But menu item and toolbox button can be enabled/disabled/checked/u nchecked 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.
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.
ASKER
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 :)
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.
ASKER
ok - done that and added the code :-
void CENGCWARE2View::OnUpdateRe cordFirst( 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)
void CENGCWARE2View::OnUpdateRe
{
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)
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.
Remember that OnUpdate... function should be fast because it is called in application idle time.
ASKER
How do u disable the button?
m_button.enable = false?
By the way, thanks for ur help today
m_button.enable = false?
By the way, thanks for ur help today
m_button.EnableWindow(FALS E);
ASKER
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 :)
Ive become an expert now thanks to you and will gladly help out any1 else when i can :)
ASKER
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