Solved

VB6 & Database

Posted on 2000-02-19
5
276 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

772 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

11 Experts available now in Live!

Get 1:1 Help Now