Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / January 2005

Tip: Looking for answers? Try searching our database.

Auto-populating fields on next form in series?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Pat Dools - 09 Jan 2005 16:17 GMT
Hello,

I have some code (see following) that will lookup to a table with Form name
and a number assigned to that form to open the 'next' form in a series via a
Command Button:

Private Sub Form_Current()
       Call SetAutoValues(Me)
End Sub

Private Sub Next_Click()
   On Error GoTo Err_Next_Click
   Call OpenNextForm(Me.Name)
   Exit_Next_Click:
     Exit Sub
   Err_Next_Click:
     DoCmd.Close acForm, Me.Name
     Resume Exit_Next_Click
End Sub

Code for the Subs insside a Module that called by the above Subs:

Sub OpenNextForm(strName As String)
Dim intOrder As Integer, frmName As String
    On Error GoTo OpenNextForm_Err
    intOrder = DLookup("[FormOrder]", "LU_Forms", "[FormName]= '" & strName
& "'")
    frmName = DLookup("[FormName]", "LU_Forms", "[FormOrder]= " & intOrder
+ 1)
    If Not IsNull(frmName) Then
        DoCmd.OpenForm frmName, , , , acAdd
    End If
    DoCmd.Close acForm, strName
OpenNextForm_Err:
    'MsgBox Err.Description
    Resume Next
End Sub

ALL forms in the series have the same 4 fields in the Header section of the
form.  The code opens the next Form in the series beautifully, but I would
like it to auto-populate the values of those 4 header fields to the values
set in the equivalent header fields in the first form of the series.  I have
the following code 'SetAutoValues' (below), but no matter how I call it, I
either get an error, or
the 4 header fields do not get auto-populated w/ no error message received
(where 'fScrEligCriteria' is the initial form and 'patient' is the unique
number assigned to the patient):

Sub SetAutoValues(frm As Form)
On Error GoTo SetAutoValues_err
   ' Set Automatic Values in each form in series
   With frm
       !studyday = Forms!fScrEligCriteria!studyday
       !patient = Forms!fScrEligCriteria!patient
       !pat_init = Forms!fScrEligCriteria!pat_init
       !site = Forms!fScrEligCriteria!site
   End With
SetAutoValues_err:
   Resume Next
End Sub

 Any ideas on how to BOTH navigate to next form in series and autopopulate
the 4 header fields by clicking on the Command Button would be greatly
appreciated.
Signature

Pat Dools

--
Pat Dools

Nikos Yannacopoulos - 10 Jan 2005 13:46 GMT
Pat,

I suspect this has to do with the fact that the line of code:

DoCmd.Close acForm, strName

in Sub OpenNextForm closes the previous form as soon as the next one is
opened, so when your code in Sub SetAutoValues looks for form
fScrEligCriteria, that one is already closed (assuming the hardcoded
form name is correct, and the control names are the same on all forms!).

Since the four controls' data is to be carried along unchanged
throughout the four forms, I would do what you are after from within Sub
OpenNextForm, by reading the controls' values from the previous form
just before closing it (as opposed to try to read from the first one in
the series). To achieve this, I would modify the code as follows (watch
out for wrapping):

Sub OpenNextForm(strName As String)
Dim intOrder As Integer, frmName As String
     On Error GoTo OpenNextForm_Err
     intOrder = DLookup("[FormOrder]", "LU_Forms", "[FormName]= '" &
strName & "'")
     frmName = DLookup("[FormName]", "LU_Forms", "[FormOrder]= " &
intOrder + 1)
     If Not IsNull(frmName) Then
         DoCmd.OpenForm frmName, , , , acAdd
     End If

'new section
     Me.studyday = Forms(strName).studyday
     Me.patient = Forms(strName).patient
     Me.pat_init = Forms(strName).pat_init
     Me.site = Forms(strName).site
'end of new section

     DoCmd.Close acForm, strName
OpenNextForm_Err:
     'MsgBox Err.Description
     Resume Next
End Sub

HTH,
Nikos

> Hello,
>
[quoted text clipped - 60 lines]
> the 4 header fields by clicking on the Command Button would be greatly
> appreciated.
Pat Dools - 11 Jan 2005 00:37 GMT
Hi Nikos (and all),

Inserting the code as noted below, I keep getting the error message,
'Invalid use of Me keyword'.  Doesn't 'Me' just mean the active form?

Thanks, Patrick

> Pat,
>
[quoted text clipped - 105 lines]
> > the 4 header fields by clicking on the Command Button would be greatly
> > appreciated.
Nikos Yannacopoulos - 11 Jan 2005 12:51 GMT
Patrick,

Glad you cracked it. The reason why you got 'Invalid use of Me keyword'
is the sub OpenNextForm sitting in a general module rather than the
form's own module. This was the natural thing to do on your part, the
sub intended to work with several forms, and the mistake was all mine
for overseeing this obvious fact. In order to work, the guilty code
section should be changed to:

'new section
    With Forms(frmName)
        .studyday = Forms(strName).studyday
        .patient = Forms(strName).patient
        .pat_init = Forms(strName).pat_init
        .site = Forms(strName).site
    End With
'end of new section

Regards,
Nikos

> Hi Nikos (and all),
>
[quoted text clipped - 112 lines]
>>>the 4 header fields by clicking on the Command Button would be greatly
>>>appreciated.
Pat Dools - 11 Jan 2005 03:31 GMT
Hi Nikos,

I found that by having the 'initial' form open (which it does on database
startup) that the code will execute properly.  Thanks for your help on this
one-- you helped me think out where my bugs were and how to address them.

Thanks again,
Patrick

> Pat,
>
[quoted text clipped - 105 lines]
> > the 4 header fields by clicking on the Command Button would be greatly
> > appreciated.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.