![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have created a form which has 5 fields of a Table as textboxes. The table has 10 fields. I have added buttons for adding a new record, saving it and browsing to next, previous record, first record and last record in table. For the onclick event of button new record, I added below code Dim dbMyDB As DAO.Database Dim myRecordSet As DAO.Recordset Set dbMyDB = DBEngine.Workspaces(0).OpenDatabase("C:\mydatabase .accdb") Set myRecordSet = dbMyDB.OpenRecordset("Table1", dbOpenDynaset) myRecordSet.AddNew myRecordSet.Close dbMyDB.Close which is incomplete. 1. What more do i need to add so that when it is clicked the user gets five empty text boxes to which he can enter data which will add a new record to the table(after the update button is clicked). 2. Similarly, for the buttons update, move to next, previous record, first record, last, record, saving the added record is there a site/link to tutorial which explains how to do these basic tasks for Access 2007. Thanks |
#3
| |||
| |||
|
|
I have created a form which has 5 fields of a Table as textboxes. The table has 10 fields. I have added buttons for adding a new record, saving it and browsing to next, previous record, first record and last record in table. |
#4
| |||
| |||
|
|
g wrote: I have created a form which has 5 fields of a Table as textboxes. The table has 10 fields. I have added buttons for adding a new record, saving it and browsing to next, previous record, first record and last record in table. For the onclick event of button new record, I added below code Dim dbMyDB As DAO.Database Dim myRecordSet As DAO.Recordset Set dbMyDB = DBEngine.Workspaces(0).OpenDatabase("C:\mydatabase .accdb") Set myRecordSet = dbMyDB.OpenRecordset("Table1", dbOpenDynaset) myRecordSet.AddNew myRecordSet.Close dbMyDB.Close which is incomplete. 1. What more do i need to add so that when it is clicked the user gets five empty text boxes to which he can enter data which will add a new record to the table(after the update button is clicked). 2. Similarly, for the buttons update, move to next, previous record, first record, last, record, saving the added record is there a site/link to tutorial which explains how to do these basic tasks for Access 2007. Thanks Is your form bound to a table/query or unbound? |
|
If bound, why not use navigation buttons? Ex: use the New Form wizard to help you create a data entry form to get you started. |
|
If bound, you could use a command similar to DoCmd.GoToRecord , , acNewRec for code behind a command button to add a new record. Look at GoToRecord for further options. You might want to check to see if the record has been modified. If Me.Dirty then... You might want to see if the record is new or old. If Me.NewRecord then... If you want to move to a particular field, in this case field Test Me.Test.Setfocus I don't know about tutorials. I'd recommend a look at Google or some other search engine. |
#5
| |||
| |||
|
|
On Thu, 24 Jun 2010 13:16:10 -0400, g<g_1@g.com> wrote: I have created a form which has 5 fields of a Table as textboxes. The table has 10 fields. I have added buttons for adding a new record, saving it and browsing to next, previous record, first record and last record in table. It really sounds like you're writing a lot of code and going to a whole lot of work to do something that a simple bound form does for you all by itself. Why? Have you used the builtin tools (a continous Form with navigation buttons turned on, as they will be by default) and intentionally rejected them? If so why? |
#6
| |||
| |||
|
|
On 6/24/2010 2:27 PM, John W. Vinson wrote: On Thu, 24 Jun 2010 13:16:10 -0400, g<g_1@g.com> wrote: I have created a form which has 5 fields of a Table as textboxes. The table has 10 fields. I have added buttons for adding a new record, saving it and browsing to next, previous record, first record and last record in table. It really sounds like you're writing a lot of code and going to a whole lot of work to do something that a simple bound form does for you all by itself. Why? Have you used the builtin tools (a continous Form with navigation buttons turned on, as they will be by default) and intentionally rejected them? If so why? I see the button wizard now activated after i drag and drop a button. The Use Control Wizards(with a wand icon) was turned off. Once i turned it on, did drag/drop for a button it worked fine. I did not know that a simple bound form did that, by itself. |
#7
| |||
| |||
|
#8
| |||
| |||
|
| When a button is clicked on a Access Form, I want to run a query and display its result. I am able to do that, but my form has 12 buttons and I am creating 12 different query objects(containing the 12 queries) for them. So, the left had side of my window(which displays all Access objects) which shows 12 query objects. Now, I have to create another form which has 6 buttons which on clicked will run 6 different queries. 1. Is there a way in Access 2007 where instead of creating another 6 query objects I can create a single query object which can contain the 6 different queries and run query 1 when button 1 is clicked, run query 2 when button 2 is clicked and so on. 2. If there is no such way, can I alleviate the issue of having multiple query objects by running a macro when the button is clicked which runs a query based on which button is clicked and produces the results. How difficult would this be to do? Currently, all I have to do is create a query object and add some SQL to it so that it produces the desired result. Any suggestions would be appreciated. |
#9
| |||
| |||
|
|
On Wed, 30 Jun 2010 12:04:32 -0400, g<g_1@g.com> wrote: When a button is clicked on a Access Form, I want to run a query and display its result. I am able to do that, but my form has 12 buttons and I am creating 12 different query objects(containing the 12 queries) for them. So, the left had side of my window(which displays all Access objects) which shows 12 query objects. Now, I have to create another form which has 6 buttons which on clicked will run 6 different queries. 1. Is there a way in Access 2007 where instead of creating another 6 query objects I can create a single query object which can contain the 6 different queries and run query 1 when button 1 is clicked, run query 2 when button 2 is clicked and so on. 2. If there is no such way, can I alleviate the issue of having multiple query objects by running a macro when the button is clicked which runs a query based on which button is clicked and produces the results. How difficult would this be to do? Currently, all I have to do is create a query object and add some SQL to it so that it produces the desired result. Any suggestions would be appreciated. First off, you're not obligated to *display* the Navigation Pane at all. You can minimize it or hide it altogether. The queries will still run if their names aren't shown! |
|
Secondly, do you really need 18 different queries? How are they diffrerent? If the only change is a criterion, you may need just ONE query with a parameter. |
|
Finally, it's generally not good design to show users query datasheets *at all*. They aren't really designed as data presentation methods. Instead, you could have a Form based on the query, and your button could either open that Form, or set its Recordsource property to the appropriate query, thereby displaying the data in a controlled, user-friendly manner. |
#10
| |||
| |||
|
|
1. Is there a way in Access 2007 where instead of creating another 6 query objects I can create a single query object which can contain the 6 different queries and run query 1 when button 1 is clicked, run query 2 when button 2 is clicked and so on. 2. If there is no such way, can I alleviate the issue of having multiple query objects by running a macro when the button is clicked which runs a query based on which button is clicked and produces the results. How difficult would this be to do? Currently, all I have to do is create a query object and add some SQL to it so that it produces the desired result. |
![]() |
| Thread Tools | |
| Display Modes | |
| |