Losing formatting on form after table updated (1 Viewer)

dcavaiani

Registered User.
Local time
Today, 01:12
Joined
May 26, 2014
Messages
385
I have events coded on the form fields as well as some conditional formatting. After I run VBA code to update records in the related Table and then return to the Form, these controls are not showing. When I go into the properties, the events and conditional stuff is still there, and then after saving the form, the controls, etc. show up ??? Very weird !!!
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:12
Joined
Oct 29, 2018
Messages
21,358
Do you think maybe it's the code that's causing it? If so, what does your code look like?
 

dcavaiani

Registered User.
Local time
Today, 01:12
Joined
May 26, 2014
Messages
385
Code:
Sub prep()
On Error GoTo ErrorHandler
Dim db As DAO.Database
Dim timecards As DAO.Recordset
Dim myDate As Variant
Dim dated As Date
   Set db = CurrentDb
   Set rstprep = db.OpenRecordset("timecards")
rstprep.MoveFirst
myDate = InputBox("Enter New Week's Saturday Start Date in Format: MM/DD/YYYY")
Do Until rstprep.EOF

If rstprep!Field1 = "Dates" Then
rstprep.Edit
dated = DateValue(myDate)
rstprep!sain = dated
rstprep!suin = DateAdd("d", 1, dated)
rstprep!moin = DateAdd("d", 2, dated)
rstprep!tuin = DateAdd("d", 3, dated)
rstprep!wein = DateAdd("d", 4, dated)
rstprep!thin = DateAdd("d", 5, dated)
rstprep!frin = DateAdd("d", 6, dated)
rstprep.Update
      End If
      
      If rstprep!Field1 = "Customer" Or rstprep!Field1 = "Am" Or rstprep!Field1 = "Pm" Or rstprep!Field1 = "Daily" Or rstprep!Field1 = "Weekly" Or rstprep!Field1 = "TOTALS" Then
         rstprep.Edit
         
   rstprep!sain = ""
   rstprep!saout = ""
   rstprep!suin = ""
   rstprep!suout = ""
   rstprep!moin = ""
   rstprep!moout = ""
   rstprep!tuin = ""
   rstprep!tuout = ""
   rstprep!wein = ""
   rstprep!weout = ""
   rstprep!thin = ""
   rstprep!thout = ""
   rstprep!frin = ""
   rstprep!frout = ""
rstprep.Update
      End If
      
      rstprep.MoveNext
   Loop
'_________________________________
On Error GoTo ErrorHandler
ErrorHandlerExit:
    Exit Sub
ErrorHandler:
    If Err = 3021 Then    ' no current record
            Else
'        MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
        Resume ErrorHandlerExit
    End If
End Sub
 

dcavaiani

Registered User.
Local time
Today, 01:12
Joined
May 26, 2014
Messages
385
It looks nice. Thanks. How do you execute this code/sub, which event do you use?

Have not figured that point out just yet. Now, I just open the module and click the "run" which executes it. Not too smart about all that "integration" yet but maybe it will/has to be run from a Macro ?
 

dcavaiani

Registered User.
Local time
Today, 01:12
Joined
May 26, 2014
Messages
385
I changed the code to a Function and that seems to correct this. Could that be it? Really confused on sub vs function ...
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:12
Joined
Oct 29, 2018
Messages
21,358
I changed the code to a Function and that seems to correct this. Could that be it? Really confused on sub vs function ...
There's a few differences, but glad to hear you got it sorted out. Cheers!
 

Mark_

Longboard on the internet
Local time
Yesterday, 23:12
Joined
Sep 12, 2017
Messages
2,111
dcavaiani,

To be clear, each record holds 14 date/times so one record is used for one week?
What happens if a person has to clock out for part of their normal shift?

You may find it easier to use one record per in/out, thus allowing you to have an employee clock in at 8am, clock out for lunch as 12:30pm, clock back in at 1:30pm, then clock out for the day at 5pm. This would also handle if the employee came back at 8pm and clocked in for an hour to handle... STUFF...
 

Users who are viewing this thread

Top Bottom