Solved

VB6 & Database

Posted on 2000-02-19
5
287 Views
Last Modified: 2010-05-02
I use DAO in VB6 to access my MDB files, I have many forms each has all buttons such as next, first, lase, prev, new...  etc to manipulate recordsets. I need to place these buttons on on toolbar in a MDI form so it controls all recordsets of every child form. As i am week in global module programming, i need someone to tell me how can i achieve this in simple steps so i can reduce my code to one instead of per the number of forms.

many thanks
0
Comment
Question by:abidsml
  • 3
5 Comments
 
LVL 3

Expert Comment

by:paulstamp
ID: 2537951
Do you want to have one single navigation control which controls all forms at once, or one that controls only the form that has the focus at the time ?
0
 
LVL 3

Accepted Solution

by:
paulstamp earned 85 total points
ID: 2537960
If you want to control all at once, have an invisible data control on each data form and store a common value in the tag property of each form (ie "Data"). Then put navigation buttons on your MDI parent toolbar, and when the user clicks on them :

Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)

Dim fmrTemp as Form

For Each frmTemp in Forms
    If frmTemp.tag = "Data" then
        Select Case Button.Key
            Case "Next"
                frmTemp.Data1.Movenext
            Case "Last"
                frmTemp.Data1.MoveLast
        End Select
    Endif
Next frmTemp

End Sub



If you want to do one at a time, create a global variable frmFocus. When a child form is activated, set frmFocus = Me. This will keep track of the active child window. When the user clicks on a button on the toolbar do :

    Select Case Button.key
        case "Next"
            frmFocus.Data1.Movenext
   
         etc etc

Hope this answers your question


0
 

Author Comment

by:abidsml
ID: 2538238
thanks, it does work with data control, i do not use data controls, i use DAO here is the code to move next:
Private Sub cmdNext_Click()


    Rs1.MoveNext
    DisplayFields
        If Rs1.EOF Then    'Don't go past first record
            AllMessages (1)
            Rs1.MovePrevious
            DisplayFields
            NavEof
            Exit Sub
        End If
    DisplayFields
    Text1(1).SetFocus

End Sub

so is there a way that i can use Rs1.movenext instaesd of data1.recordset.movenext.

thanks for the help
0
 
LVL 3

Expert Comment

by:paulstamp
ID: 2538340
Thats a bit harder, because I doubt that all your forms have the same controls on them.

The best you can do is probably to have a standard public sub in each data form which is called by the toolbar_buttonclick event to fire off your routines, for example instead of frmFocus.Data1.Recordset.MoveNext have a single public routine "Navigate" which has a select case statement and depending upon the button clicked runs a routine like you described above.

For example :

Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)

    frmFocus.Navigate(button.key)

end Sub

===========

for each form

Public Sub Navigate(byval sKey as string)

select case sKey
    Case "next"
        Rs1.MoveNext
        DisplayFields
        If Rs1.EOF Then    'Don't go past first record
            AllMessages (1)
            Rs1.MovePrevious
            DisplayFields
            NavEof
            Exit Sub
         End If
         DisplayFields
         Text1(1).SetFocus
    Case "last"
   
    <etc etc>

Hope that helps.



0
 

Expert Comment

by:Yogesh_k
ID: 2539842
define one recordset object per form with same name and u can easily get which form is active or having focus
with help of property
Screen.ActiveForm
get that form and put following code in tool click event for Move next tool button.

set frmCurrent = Screen.ActiveForm
frmCurrent.rstSameForAll.MoveNext

If any problem write to me at ytok@mailcity.com
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
using Access 8 83
VB6 common control 6 sp6 object library not registerd 3 42
adding "ungroup sheets" to existing vbs code 5 52
VB script to continue despite error 2 48
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

740 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