Hi I am trying to create a small app for recording lieu time.
The code below does not return a total value for the users lieu time.
2 tables
lieu
Lieudate date.
lieuAdd boolean choice list True, False.
LieuHours decimal.
lieuTotal decimal computed field.
Users
UserName string.
LastName string.
Firstname String.
Phone Phone.
Email emailaddress.
one(users) to many(lieu)
I want to show the total amount of lieu time a person has in the lieutotal field
a running total so when a user looks at their last record it shows the last transaction and how much lieu time they have.
code for computed field
Namespace LightSwitchApplication
Public Class Lieu
Private Sub LieuTotal_Compute(ByRef result As Decimal)
' Set result to the desired field value
Dim Total As Decimal
If LieuAdd = True Then
If LieuTotal = 0 Then
Total = LieuHours
Else
Total = LieuTotal + LieuHours
result = total
End If
Else
Total = LieuTotal - LieuHours
End If
End Sub
End Class
End Namespace
Since you are computing a total, you need to use a For Each loop. Assuming the name of the table is Lieus, your code should be something like:
Private Sub LieuTotal_Compute(ByRef result As Decimal)
' Set result to the desired field value
'
For Each Lieu In Lieus
If Lieu.LieuAdd = True Then
result = result + Lieu.LieuHours
Else
result = result - Lieu.LieuHours
End If
Next
End Sub
Hope this helps
Related
I have a database I'm working on with a number of forms, some of them have to be updated when something in a different form is changed. I've set it up so that they're multi-instance forms, which works something like this:
Set frm = New Form_Name
frm.RecordSource = "select * from Table_Name where id = " & ID
colForms.Add Item:=frm, Key:=frm.hwnd & ""
mintForm = mintForm + 1
frm.SetFocus
frm.Visible = True
colForms is a collection.
To refresh a form, I've added a function that refreshes the form that matches the name and ID passed:
Function RefreshForm(RForm As String, ID As Integer)
If Developer = False Then On Error GoTo Fehler
Dim F As Form
On Error Resume Next
For i = 1 To mintForm
Set F = colForms(i)
If F.CurrentRecord = ID And F.Name = RForm Then F.Refresh
Next i
'Error handling logic
Done:
Exit Function
Fehler:
RuntimeError "MultiInstance: RefreshForm", Err.Number, Err.Source, Err.Description, Err.HelpFile, Err.HelpContext, Err.LastDllError
Err.Raise 1000, , "Folgefehler"
End Function
Problem is, F.CurrentRecord is always 1 for some reason, even though the ID of the record in the form is definitely not 1. Any idea what I'm doing wrong, or how I could properly get the record ID (primary key) from the form? The form is definitely bound (at least the ones where I'm trying to get the ID).
CurrentRecord is not pulling record's ID from unique identifier field. CurrentRecord is a sequential number assigned by the form and has no relationship to the record unique identifier saved in field.
If focus is on fifth record then it is record 5 and if that record has a unique ID field value of 5 then they are equivalent. Doing this comparison seldom makes sense. A form always sequentially numbers records starting with 1 regardless of filtering/sorting yet the form could be filtered to display a subset of records and/or records could be sorted so ID's are not sequential nor start with 1.
If you want to know ID of record that has focus then reference field name holding that data.
If F!fieldname = ID And F.Name = RForm Then F.Refresh
I am currently trying to create a number that increases per entry and group in my table via a form.
The form is rather simple it utilizes a ComboBox to select the group from a different table. The generated number should start at 1 and increase for every new entry separately for each selected group.
Code:
My code attempts to create the number BeforeUpdate by searching for the DMax() of the variable for the group selected via ComboBox. Unfortunately, in this current state, the code does not increment the variable called Nummer but it does not throw an Error either.
Private Sub Nummer_BeforeUpdate(Cancel As Integer)
Nummer = Nz(DMax("[Nummer]", "Bau-Tagesbericht", "[Baustelle] = Kombinationsfeld354.Value")) + 1
End Sub
Variables:
Group: Baustelle
Variable that should be incremented: Nummer
Name of the Comobox: Kombinationsfeld354
I appreciate any kind of help, thank you!
You need to concatenate the variable - and set 0 (zero) for Null:
Nummer = Nz(DMax("[Nummer]", "Bau-Tagesbericht", "[Baustelle] = " & Kombinationsfeld354.Value & ""), 0) + 1
If text value, use single quotes:
Nummer = Nz(DMax("[Nummer]", "Bau-Tagesbericht", "[Baustelle] = '" & Kombinationsfeld354.Value & "'"), 0) + 1
I have a form where i retrieve the start date and ending date from a table in access.
The start date and end date are both known as startdate and endate.
Then i have another column which is status.
My code is like this:
sd = Me.startdate
ed = Me.enddate
DateValue (sd)
DateValue (ed)
If IsNull(sd And ed) Or (ed > Date) Then
Me.Text59 = "In use"
ElseIf (ed < Date) Then
Me.Text59 = "Free"
so basically what i wanted to do is, if the end date is earlier than today, the status will display it as Free. However, if the end date is later than today, the status will be in use. columns where the start date and end date are empty will be displayed as in use too.
My table's start date and end date are in date/time data type.
When the code runs, they only display "In use" when clearly some of my dates end earlier than today! Help please ):
You are not telling if either startdate or enddate can be Null while the other is not, so both will either be Null or hold a value. Further, startdate seems to always be earlier than enddate, thus of no importance.
Then:
Dim sd As Variant
Dim ed As Variant
Dim inuse As Boolean
sd = Me!startdate
ed = Me!enddate
If IsNull(sd) And IsNull(ed) Then
inuse = True
ElseIf DateDiff("d", Date, ed) > 0 Then
inuse = True
End If
If inuse = True Then
Me!Text59 = "In use"
Else
Me!Text59 = "Free"
End If
For a single-line code to use as ControlSource for Text59 (Nz is only used to avoid an error if ed is Null):
=IIf(IsNull([startdate]+[enddate]),"In use",IIf(DateDiff("d",Date(),Nz(ed, Date()))>0,"In use","Free"))
I need to add a filter to filter data by a persons age.
Below is the code i am using for to filter tel and phone numbers.
The feild that collects/holds my customers DOB is "app.DOB"
Please assist me
Friend Overrides Function Filter() As String
Dim sb As New StringBuilder()
If (Not app.LandPhone.StartsWith("01")) And (Not app.LandPhone.StartsWith("02")) Then
sb.Append("Land phone must be present and start 01 or 02;")
End If
If (Not app.WorkPhone.StartsWith("01")) And (Not app.WorkPhone.StartsWith("02")) And (Not app.WorkPhone.StartsWith("08")) Then
sb.Append("Work phone must be present and start 01, 02 or 08;")
End If
If app.MobilePhone = String.Empty Then
sb.Append("Mobile phone must be present;")
End If
Return sb.ToString()
End Function
If DOb is of datetime, then the DateDiff function will be usefull.it will be like
if DateDiff(DateInterval.day,app.DOB,Date.Today)/365 > your filter value
''what you want to do
end if
Note:
now only i noticed your comment that it is string.i that case convert it to date using parseexact before using in datediff function like
if format of you DOB column is dd/MM/yyyy then
Dim dt = DateTime.ParseExact(app.DOB, "dd/MM/yyyy", Nothing)
if DateDiff(DateInterval.day,dt,Date.Today)/365 > your filter value
'' what you want
end if
you can change the format according to your grid format:
See the select below.
dim query = from a in MyContext.MyTables
Where Not a.ID = 1
Select a
I want to check if a value of a field is null. I am doing the following:
if query.count > o then
if a(0)("field") is nothing then
messagebox.show("INVALID VALUE FOR RETURNING")
end if
end if
It is generation an exepction that I can't compare the value a(0)("field").
How should I do it?
Thanks.