Results 1 to 3 of 3
  1. #1
    CurtisC is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2020
    Posts
    11

    passing values between forms

    I have a main form for navigation between my other forms. For my frm_Weekly_Report I have a main menu text box with a date picker to select a date and a "Go" Button. When the user clicks the button it evaluates this date to ensure that it a Friday date and is stored in a variable called StartDate which is defined as a string. If it is a friday then it would open the frm_Weekly_Report.

    On the form load for frm_Weekly_Report I want it to evaluate this StartDate to see if it has been entered already. If it has I want it to go to that record, if not I want it to go to a new record



    On frm_Main I have the following code.

    Code:
    Private Sub Go_To_Weekly_Click()Dim StartDate As String
    Dim WEFri As Integer
        Me.Test.Value = ""
        StartDate = Me.txtStartDate.Value
         WEFri = Weekday(StartDate)
             Me.Test.Value = WEFri
        If WEFri <> 6 Then
               MsgBox ("Please select a Friday")
               txtStartDate.SetFocus
        Else
                DoCmd.OpenForm "frm_Weekly_Report"
             End If
    End Sub
    and in the frm_Weekly_Report i have this.

    Code:
    Private Sub Form_Load()
    
    
    MyValue = Form_frmMain_txtStartDate.Value
        
        Dim UniqueIDCount As String
        Dim DateYr As String
        Dim DateDy As String
        Dim DateMo As String
        
        DateDy = Day(MyValue)
        DateMo = Month(MyValue)
        DateTemp = MyValue
        DateYr = Year(MyValue)
        WkNumber = DateYr & "-" & DatePart("ww", DateTemp, vbSaturday, vbFirstFourDays)
        
         
        UniqueIDCount = DCount("Wk_Number", "tbl_Weekly_Report", "Wk_Number ='" & WkNumber & "'")
            If UniqueIDCount > 0 Then
                Dim varX As Variant, rs As Dao.Recordset, lngID As Long
                Set rs = Me.RecordsetClone
                lngID = (DLookup("Weekly_Report_ID", "tbl_Weekly_Report", "Wk_Number ='" & WkNumber & "'"))
                rs.FindFirst "[Weekly_Report_ID]=" & lngID
                varX = rs.Bookmark
                Me.Bookmark = varX
                Set rs = Nothing
            Else
                    DoCmd.GoToRecord acDataForm, "frm_Weekly_Report", acNewRec
                    Me.Wk_End_Date.Value = DateMo & "/" & DateDy & "/" & DateYr
                    Me.WE_Year.Value = DateYr
                    Me.Wk_Number.Value = WkNumber
            End If
    End Sub
    how do I pass the StartDate value to be the MyValue in the Weekly Report form?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    One way is with OpenArgs argument of OpenForm command.

    Other options are Global variable and TempVars as well as code behind one form directly referencing control on other form.

    All are common topics and should find many examples on web.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    use the full path to the form:

    forms!fMyForm!txtBox1

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Passing id between to forms
    By spandor in forum Forms
    Replies: 5
    Last Post: 07-06-2019, 02:40 PM
  2. passing values between forms
    By paulw in forum Access
    Replies: 4
    Last Post: 06-15-2011, 08:52 AM
  3. PASSING Values between Forms
    By chhinckley in forum Programming
    Replies: 1
    Last Post: 08-27-2010, 10:19 AM
  4. Replies: 3
    Last Post: 06-02-2009, 09:51 AM
  5. Passing Values
    By dromorkid in forum Forms
    Replies: 0
    Last Post: 11-25-2008, 05:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums