Solved

simple form with data access (i think!!)

Posted on 2002-05-17
10
182 Views
Last Modified: 2010-04-02
i m very new to c++
i want to show a form contains (ID : , Name :, Age : )
and store the inputs in an .mdb file with butoms that move to first record or Next , Last, Prev., Add, Del, Find, and Close.  is it hard to do that ????
please help....
0
Comment
Question by:raed
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 16

Expert Comment

by:AlexNek
ID: 7016272
0
 
LVL 2

Expert Comment

by:WBaldwin
ID: 7017336
Make your MFC Access Database "FIRST" (Its easier this way). Set up your selected fields your going to want to have in your database and assign the limitations / restrictions for each.

After you have completed your database.

Goto your VC++ program.

Select NEW.

Select the MFC APPWizard.exe
Give your Program a name.
Select OK.
Select Single Document Interface.
Select Next.
Select Databaseview with file support.
Click on the Data Source.
A dialog window will pop up asking you the location of the Database file. Once you locate the file and select it. It will as you the table to reference.
Select it.
Once finished select Next.
Next
Next
You should be at a screen where it will have the Base Class in the bottom left hand corner.
Select CFormView.
(If gone to far back up one)

Select Next.
Finish.
Now you have your Database linked with a blank Form.
Note you have your advanced arrows on the Frame.
The advance and previous will work. Getting the form to delete a record is a little bit of work.

Now using the toolbar enter in the same number of edit boxes as fields in your database.

Use the static text boxes to the left or right to identify your edit boxes.

Select Edit and then Class wizard.
Select Class Info.
Give your working class a foreign variable:
(common type) m_pSet
Now go to member variables.
Assign your variable for each of your edit boxes.
Do this by selecting the appropriate IDC_[name you gave it]
then select ADD VARIABLE here is where your going to associate it with the variable in your Database field.
You will now see m_pSet-> "Variable name in your database"
Note:
You must set your variable type as it is in the Database in order to get the "m_pSet->" to appear.
Ie.. string with string
int with int


Repeat this process for each Edit box.

Your linked now with each variable after you finish and select OK.

If you want a better examble of how to set up the delete portion or want more detailed information of this use your help in the VC++ program or even better for starting out a good book to use for beginners there is the
SAMS:
Teach yourself Visual C++ 6 in 21 Days.

There is a section that covers it specifically.
And yes its accually easy to do.
Good luck.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7017676
This question is current, others below are not and need your attention please.  ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101, Netminder or Mindphaser will return to finalize these if they are still open in 7 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20253068.html
http://www.experts-exchange.com/questions/Q.20299675.html
http://www.experts-exchange.com/questions/Q.20274828.html
http://www.experts-exchange.com/questions/Q.20285531.html
http://www.experts-exchange.com/questions/Q.20285532.html
http://www.experts-exchange.com/questions/Q.20285816.html
http://www.experts-exchange.com/questions/Q.20301612.html



*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
0
 

Author Comment

by:raed
ID: 7018747
WBaldwin,  

how can i add buttons to do the the following functions :
First record, Next record, Last Record, Find Record , New Record, Close Form.



thanx
0
 

Author Comment

by:raed
ID: 7020995
is it so hard ??? or need more points ????
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 2

Accepted Solution

by:
WBaldwin earned 200 total points
ID: 7021562
Dont worry about more points, I am just happy to be able to answer a question.

That is why you will be choosing the single form view. The Advance and Previous button will be automatically attached to the Frame and functional.

If your wanting to add buttons to the Form it self then:

Useing the toolbar drag a button onto your form.
Right click the button and goto properties.
Assign the IDC_"Name"  something related to what its going to be ie..
IDC_ADDNEW
In the other feild for the viewable name put: ADD NAME
Now goto the View on your menu bar and select -> Class Wizard:
with the Message Maps tab selected find your name you gave it ie..
IDC_ADDNEW
Select it. You will notice on the screen to the right of it with two selections.
BN_CLICKED
BN_DOUBLECLICKED

Select BN_CLICKED

Then select  The -> Add Function (BUTTON TO THE RIGHT)
Then select ->Edit Code (button)

This will take you automatically to the spot where the code is going to be implemented.

Add this command to your code:
void CComm_SetView::OnBexit() //Remember CComm_SetView is my name of program
{
     // TODO: Add your control notification handler code here
     m_pSet.Addnew();

}

Repeat this process for your other commands you want to add.
other commands are as follows:

m_pSet.MoveLast();
m_pSet.Update();
m_pSet.Delete();
m_pSet.MovePrev();

Allow the user to edit a record:

m_pSet.Edit();
// Assign your changes
.
.
.
// Save the changes
m_pSet.Update();

// This will close the window if you assign a button ie.. EXIT. Then set a command to the button using the // wizard           Note CComm_SetView is my Program yours will be different
void CComm_SetView::OnBexit()
{
     // TODO: Add your control notification handler code here
     AfxGetMainWnd()->DestroyWindow();

}


Example of setting defaults to your DB variables:
///////////////////////////// You can also set Defaults to a record using a button ///////////////////////////////////////////
void CComm_SetView::ClearAll()
{
     m_pSet->m_Record_Name = "";
     m_pSet->m_Radio_Number = "";
     m_pSet->m_Call_Sign = "";
     m_pSet->m_Channel_Preset = "0";
     m_pSet->m_Radio_Tune_Mode = "";
     m_pSet->m_Security = "";
     m_pSet->m_Antenna = "";
     m_pSet->m_XMIT_Power = "";
     m_pSet->m_Key = "";
     m_pSet->m_Delay = "";

                   UpdateData(FALSE); // This resets the Dialog window with the new values
}

Example of deleting a file (example is from book I quoted you before)

void CTestdb5Biew::OnRecordDelete()
{  
             if(MessageBox("Are you sure you want to delet this record?" , "Delete this record?", MB_YESNO |                  MB_ICONQUESTION) == IDYES)
             {
               // Delete the record
               m_pSet->Delete();
              // Move to the previous record
               m_pSet->MovePrev();
              // Update the form view
               UpdateData(FALSE);
            }
}

I hope this helps, let me know if there is something within your question that I forgot.
But to be honest that book is a great starter for helping you create a form linked with a database.
(And no I make no money of the sale of that book   :)   )
Good luck.
Remember to add one peice at a time and test it. Then keep adding each additional functionality before moving onto the next.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7068911
Can you please response here and finalize this?
Thanks,
Moondancer - EE Moderator
0
 
LVL 11

Expert Comment

by:griessh
ID: 7178791
Dear raed

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "WBaldwin"

comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points. The link to the Community Support area is: http://www.experts-exchange.com/commspt/


PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 2

Expert Comment

by:WBaldwin
ID: 7179894
I think he forgot me.. --- sniff ---
But as far as this question goes, Ive given you all the tools you need there.
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7199797
Stop crying now :-)

Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

758 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

17 Experts available now in Live!

Get 1:1 Help Now