Avatar of SweetingA
SweetingA
 asked on

Access Runtime 2007 Problems

detailed below is the code i have attached to a form.

This form will not run in access runtime.  Works perfectly in access and compiles without problems.

Any ideas welcome.


Private Sub Form_Current()
     Me.txtStartDate = Format(Me.txtStartDate, "dd-mmm-yy")
     Me.txtEndDate = Format(Me.txtEndDate, "dd-mmm-yy")
End Sub

Private Sub Form_Load()

    Dim LastDateOfMonth As Date
    Dim FirstDateOfMonth As Date
    Dim strMonth As String
    Dim strYear As String

    strMonth = CStr(Month(Now()))
    strYear = CStr(Year(Now()))

    Select Case strMonth
        Case "1", "3", "5", "7", "8", "10", "12"
        LastDateOfMonth = CDate("31/" & strMonth & "/" & strYear)
        FirstDateOfMonth = CDate("01/" & strMonth & "/" & strYear)
        Case "4", "6", "9", "11"
        LastDateOfMonth = CDate("30/" & strMonth & "/" & strYear)
        FirstDateOfMonth = CDate("01/" & strMonth & "/" & strYear)
        Case "2"
        If (CLng(strYear) Mod 4 <> 0) Then
            LastDateOfMonth = CDate("28/" & strMonth & "/" & strYear)
            FirstDateOfMonth = CDate("01/" & strMonth & "/" & strYear)
        Else
            LastDateOfMonth = CDate("29/" & strMonth & "/" & strYear)
            FirstDateOfMonth = CDate("01/" & strMonth & "/" & strYear)
        End If
       
    End Select

    Me.txtStartDate = FirstDateOfMonth
    Me.txtEndDate = LastDateOfMonth
    Me.TechnologyGroup = "*"
    Me.Machine = "*"
    Me.ProductID = "*"
    Dim A As String
    Dim B As String
    A = Me.txtStartDate
    B = Me.txtEndDate
    Me.Form.Filter = "[Date] Between #" & Format(A, "dd-mmm-yyyy") & "# AND #" & Format(B, "dd-mmm-yyyy") & "# "
    Me.Form.FilterOn = True
    Call LeftClick
End Sub

Private Sub TechnologyGroup_BeforeUpdate(Cancel As Integer)
    Me.Machine = "*"
    Me.ProductID = "*"
End Sub

Private Sub Machine_BeforeUpdate(Cancel As Integer)
    Me.TechnologyGroup = "*"
    Me.ProductID = "*"
End Sub

Private Sub ProductID_BeforeUpdate(Cancel As Integer)
    Me.TechnologyGroup = "*"
    Me.Machine = "*"
End Sub

Private Sub txtStartDate_AfterUpdate()
  Dim A As String
  Dim B As String
  Me.TechnologyGroup = "*"
  Me.Machine = "*"
  Me.ProductID = "*"
  A = Me.txtStartDate
  B = Me.txtEndDate
  Me.Form.Filter = "[Date] Between #" & Format(A, "dd-mmm-yyyy") & "# AND #" & Format(B, "dd-mmm-yyyy") & "# "
  Me.Form.FilterOn = True
  Call LeftClick
End Sub

Private Sub txtEndDate_AfterUpdate()
  Dim A As String
  Dim B As String
  Me.TechnologyGroup = "*"
  Me.Machine = "*"
  Me.ProductID = "*"
  A = Me.txtStartDate
  B = Me.txtEndDate
  Me.Form.Filter = "[Date] Between #" & Format(A, "dd-mmm-yyyy") & "# AND #" & Format(B, "dd-mmm-yyyy") & "# "
  Me.Form.FilterOn = True
  Call LeftClick
End Sub

Private Sub TechnologyGroup_AfterUpdate()
  Dim A As String
  Dim B As String
  Dim C As String
  A = Me.txtStartDate
  B = Me.txtEndDate
  C = Me.TechnologyGroup.Text
  Me.Form.Filter = "[Date] Between #" & Format(A, "dd-mmm-yyyy") & "# AND #" & Format(B, "dd-mmm-yyyy") & "# AND [TechnologyGroup] = " & Chr(34) & C & Chr(34)
  Me.Form.FilterOn = True
  Call LeftClick
End Sub

Private Sub Machine_AfterUpdate()
  Dim A As String
  Dim B As String
  Dim C As String
  A = Me.txtStartDate
  B = Me.txtEndDate
  C = Me.Machine.Text
  Me.Form.Filter = "[Date] Between #" & Format(A, "dd-mmm-yyyy") & "# AND #" & Format(B, "dd-mmm-yyyy") & "# AND [Machine] = " & Chr(34) & C & Chr(34)
  Me.Form.FilterOn = True
  Call LeftClick
End Sub

Private Sub ProductID_AfterUpdate()
  Dim A As String
  Dim B As String
  Dim C As String
  A = Me.txtStartDate
  B = Me.txtEndDate
  C = Me.ProductID.Text
  Me.Form.Filter = "[Date] Between #" & Format(A, "dd-mmm-yyyy") & "# AND #" & Format(B, "dd-mmm-yyyy") & "# AND [ProductID] = " & Chr(34) & C & Chr(34)
  Me.Form.FilterOn = True
  Call LeftClick
End Sub
Private Sub Command249_Click()
On Error GoTo Err_Command249_Click

    Dim stDocName As String

    stDocName = "mac_OEE_M8"
    DoCmd.RunMacro stDocName

Exit_Command249_Click:
    Exit Sub

Err_Command249_Click:
    MsgBox Err.Description
    Resume Exit_Command249_Click
   
End Sub
Microsoft Access

Avatar of undefined
Last Comment
Dale Fye

8/22/2022 - Mon
Dale Fye

What do you mean by "This form will not run in access runtime"?

Does it generate an error?

Which part of the code won't run?  Will any of the procedures work?

Does the user have the application installed in a "trusted location"?  If not, they will need to do so or none of the code will work.
SweetingA

ASKER
Some users do not have MS Access so i created a runtime variant for them using Microsofts free runtime software.

This is the only query/form/report out of a much larger database that does not run.

Yes its in a trusted location.

The error is "execution of this application has stopped due to a runtime error"

i am not very familiar with runtime so i don't know if t has all the functionality of access.

Regards
Dale Fye

You have more runtime experience than I do.  ;-)

Do you get this error as soon as you attempt to open the form?  Or is the error associated with a particular action on the form?

Did you compile the application prior to creating the runtime version?  If not, try that to see whether there is a compilation problem with that form.

BTW, you can replace a lot of code in the Form_Load event if you would use:

LastDateOfMonth = DateSerial(Year(Date()), Month(Date()) + 1, 0)
FirstDateOfMonth = DateSerial(Year(Date()), Month(Date()), 1)

or for the first day of the month:

FirstDateOfMonth = Date() - Day(Date()) + 1
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
selva_kongu

Are you using the Miscosoft DAO 3.6 Object Library, in your project?

VB6 MS DAO
ASKER CERTIFIED SOLUTION
Dale Fye

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Dale Fye

Also, I've never seen anyone apply a filter using:

Me.Form.FilterOn = True

I always use:

me.FilterOn = true

although your method may work, I cannot recall ever seeing it used that way, because Me actually refers to the form (or report)
SweetingA

ASKER
I am not sure why but removing the .text solved the problem.

All other items were in order.

Thankyou very much.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Dale Fye

Glad I could help.

If you have experience with VB, the Text property is the default, but in Access the Value property of a control is the default.

I frequently use .Text when I'm working with a controls Change event (like in a textbox that is being used for real-time filtering), but rarely use it elsewhere.
harfang

Side note to fyed:

The keyword “Me” exists in all class modules, and refers to the class. For class modules attached to a form, a number of objects are pre-defined, namely the form and all controls on it, with events. So “Me.Form” refers to the form, and is also the default property of “Me”. The filter of the form is formally “Me.Form.Filter”, but can be written as “Me.Filter” (the most often seen syntax), ”Form.Filter” (normal when used outside of the module, e.g. in a text box expression or a macro), and even just “Filter”.

Saying that “Me” refers to the form is thus technically incorrect, but valid from a practical point of view, in most cases. It's a very common misconception.

Cheers!
(°v°)
Dale Fye

Thanks, Markus.  Appreciate the clarification.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes