FindRecord - link main and sub forms with else 
Author Message
 FindRecord - link main and sub forms with else

I have two sets of code - the first works, the second doesn't.  Here's
my problem:

The first set of code works great - it's essentially linking a main form
with a subform on the StudentID.  The second set of code almost works -
I'm trying, from the main form, to look for the record with a matching
StudentID, and if there is a matching record in the subform, allow
editing that record, and if there is no matching record, allows creation
of a new record, with the StudentID filled in the relevant field.  Any
advice would help!

Rick

First Set of Code:
__________________________________
Private Sub che_Click()
On Error GoTo Err_che_Click

    Dim stDocName As String
    Dim lngCheck As Long

    stDocName = "AddCheckTransaction"
    lngCheck = Me!StudentID

    DoCmd.OpenForm stDocName, , acLast
    DoCmd.GoToRecord , , acNewRec
    Forms!AddCheckTransaction!StudentID.DefaultValue = lngCheck

Exit_che_Click:
    Exit Sub

Err_che_Click:
    MsgBox Err.Description
    Resume Exit_che_Click

End Sub

Second Set of Code:
__________________________________________
Private Sub uni_Click()
On Error GoTo Err_uni_Click

    Dim stDocName As String
    Dim lngUniv As Long

    stDocName = "AddUniversityAccount"
    lngUniv = Me!StudentID

    DoCmd.OpenForm stDocName, , acAll
    DoCmd.GoToControl (StudentID)
    DoCmd.FindRecord Forms![EnterStudent]![StudentID], acEntire, ,
acSearchAll, , acCurrent, True

    If Me!StudentID = lngUniv Then
    DoCmd.GoToRecord , , acGoTo
    Else
    DoCmd.GoToRecord , , acLast
    DoCmd.GoToRecord , , acNewRec
    Forms!AddUniversityAccount!StudentID.DefaultValue = lngUniv

    End If

Exit_uni_Click:
    Exit Sub



Sun, 20 Oct 2002 03:00:00 GMT  
 FindRecord - link main and sub forms with else
It looks like you're trying to set the default value property of the textbox
on the form. Try leaving out DefaultValue in the assignment statement.

This wouldn't matter to the result in the first procedure if your subform
Parent and Child fields are matched and the subform allows adding records
but in the second example you seem to be opening a different form and
setting the default value of the control to the current student Id

The DefaultValue property defines what appears when a new record is created
in the form, etc.

HTH, if not let me know.

John Flanagan



Sun, 10 Nov 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. create main form and Sub Form

2. create Main Form Sub form in VB6

3. Can't access records with sub form for linked sub table

4. How to change caption on a sub from text on main form

5. Showing a form from within Sub Main.

6. Invock a dll that has sub Main(), instead of a form as entry point

7. trying to start a form, from a MAIN sub in a module

8. Sub Main(): keep app open after showing form?

9. Opening a form from a Mobule Sub Main

10. Good Main/Sub form Software

11. I want some help about Main-Sub Forms In VB

12. start up form sub main

 

 
Powered by phpBB® Forum Software