I have a pulldown text field with 15 options - Package 1, Package 2, through to Package 15.
Once a user selects a pulldown, the on change procedure is such that it populates the the fields in the form with the cooresponding data pulled in the select statement as the source of the pull down.
It works great until the user selects Package 10 or greater. the result is blank fields. Not exactly sure why and how to fix this.
Private Sub ColourPackage_Change()
Me.Brick.Value = Me.ColourPackage.Column(1)
Me.Stone.Value = Me.ColourPackage.Column(2)
Me.Shingles.Value = Me.ColourPackage.Column(3)
Me.Windows.Value = Me.ColourPackage.Column(4)
Me.GarageDoors.Value = Me.ColourPackage.Column(5)
Me.BoardBatton.Value = Me.ColourPackage.Column(6)
Me.Alluminum.Value = Me.ColourPackage.Column(7)
Me.Stucco.Value = Me.ColourPackage.Column(8)
Me.Shakes.Value = Me.ColourPackage.Column(9)
Me.Railing.Value = Me.ColourPackage.Column(10)
End Sub
Any help is greatly appreciated.
Use the AfterUpdate event:
Private Sub ColourPackage_AfterUpdate()
Related
I have problem with VBA code select case. Code is linked to combobox(Combo0) and event after update. In combobox there is a list of values: BHP, PPOZ, ISO. When i choose BHP, it should change source object property in subfrom(Child03) to subfrmBHP. Same with PPOZ and ISO. But for some reason, when i choose BHP it shows table from PPOZ, when i choose PPOZ it shows BHP and when i choose ISO it shows BHP. Code looks like this:
Private Sub Combo0_AfterUpdate()
Select Case ChangeCombo
Case Combo0 = "BHP"
Forms("frmInstrukcje").Form.Child3.SourceObject = "subfrmBHP"
Case Combo0 = "PPOŻ"
Forms("frmInstrukcje").Form.Child3.SourceObject = "subfrmPPOZ"
Case Combo0 = "ISO"
Forms("frmInstrukcje").Form.Child3.SourceObject = "subfrmISO"
End Select
End Sub
I aleredy recreated tables, form, sub form. Someone suggested me it could be data binding in subform, but there is nothing written there.
Your method references two controls, ChangeCombo and Combo0. Not sure if it's a typo or you have something else in mind.
Anyway, Case Combo0 = "BHP" is incorrect, so assuming Combo0 is the correct control, try the below.
Private Sub Combo0_AfterUpdate()
With Forms("frmInstrukcje").Form.Child3
Select Case Me.Combo0.Value
Case "BHP":
.SourceObject = "subfrmBHP"
Case "PPOŻ":
.SourceObject = "subfrmPPOZ"
Case "ISO":
.SourceObject = "subfrmISO"
End Select
End With
End Sub
I have a combo box called NameFilt. I wish the row source to be as follows:
SELECT DISTINCT VoucherListTbl.BuyerName
FROM VoucherListTbl
WHERE (((VoucherListTbl.BuyerName) Is Not Null)) OR (((VoucherListTbl.BuyerName)<>""));
i.e show all the unique BuyerNames from my table and dont include any blanks
The above SQL is generated in the query bulider by clicking on the 3 dots in combo box's row source in the property sheet, then selecting the BuyerName field and then entering Is Not Null Or <>" in the criteria. Clicking run in the query builder displays the exact result I expect.
On closing and saving the query builder and then clicking in the combo box on the form I get a different result - All the DISTINCT names are there, but there is a blank at the start of the list.
When I attempt to use this SQL in my VBA code I get another result. The code is:
Private Sub NameFilt_GotFocus()
Me.AllowEdits = True
Me.NameFilt.RowSource = "SELECT DISTINCT VoucherListTbl.BuyerName
FROM VoucherListTbl WHERE (((VoucherListTbl.BuyerName) Is Not Null))
OR (((VoucherListTbl.BuyerName)<>""));"
Me.NameFilt.Dropdown
End Sub
This results in the combo box's dropdown showing only one option - a blank! There are no names listed.
Moreover, If the WHERE clause is removed i.e. the code is:
Private Sub NameFilt_GotFocus()
Me.AllowEdits = True
Me.NameFilt.RowSource = "SELECT DISTINCT VoucherListTbl.BuyerName FROM VoucherListTbl;"
Me.NameFilt.Dropdown
End Sub
Then the DISTINCT names are shown, with a blank option at the top of the list which is what one would expect
Please could you help by explaining why the WHERE clause will not work for me when entered into the VBA code
Many thanks
If you use "" within "" it will break the string and that's the reason of non-working WHERE condition. Encode quotes with "" i.e. end of your original string should look like <>""""));" or replace "" with '' and try again.
Note, same query can be written as
SELECT DISTINCT BuyerName
FROM VoucherListTbl
WHERE IsNull(BuyerName,'')<>''
I'm trying to make a form checkbox update a date in another table.
Private Sub Delivered_AfterUpdate()
If Delivered = -1 Then
[tool implentation].[date] = Now()
End Sub
I'm getting an error on the [tool implentation].[date] = Now() line.
I would like if any time the checkbox is clicked (check and un-check) the date is updated.
I'm assuming your table is also the form's recordset here. If it is not you will need something to determine which record in the table you want to edit.
Private Sub Delivered_AfterUpdate()
If Me.Delivered = True Then
With Me.Recordset
.Edit
![ImplementationDate] = Now()
.Update
End With
End If
End Sub
You can leave Me.Delivered = -1 if you want but I find True/False to be easier to read.
I also recommend not naming something Date, I'm not sure if it actually matters as a column name, but it is both a builtin function and data type. So I changed it.
You should also indent your code, it will be a nightmare as you get more lines.
I am using code that calculates the average of exams where the module code is CSC3047 as shown below:
avgObject = gradeTable.Compute("avg(exam)", "module_ID = CSC3047")
However i would like to calculate the average exam result where the module ID equals the selected value from a radio button which has a list of the modules.
Something like this:
avgObject = gradeTable.Compute("avg(exam)", "module_ID = radioList.selectedValue")
I know this is wrong but i have no idea how to accomplish this.
Dim condition As String = "module_ID=" + radioList.SelectedItem.Value.ToString()
avgObject = gradeTable.Compute("avg(exam)", condition)
Hope this will help you
I have several records in a database that have Start and End Dates
09/15/2011 - 09/30/2011
10/15/2011 - 10/22/2011
11/01/2011 - 11/15/2011
When user stores a record, I need to make sure dates don't overlap.
My simple code checks date ranges within a specific record (e.g. user enters 9/16/2011 or 10/21/2011, I throw an exception.)
But, on the slim chance a user gets creative (e.g. 10/14/2011 - 10/23/2011 or even 10/14/2011 to 11/16/2011), now they have circumvented my check.
BTW, the user could enter 10/14/2011 to 10/23/2011 if they were editing the record that contained values 10/15/2011 - 10/22/2011.
So, I'm trying to solve this riddle with a linq query. However, what I have isn't working exactly right.
UPDATE Nevermind about code not working. While trying to provide an example to expand on Miika's repsonse, I found my answer. So, giving credit to Miika for pointing me in the right direction and posting my working code below:
Here's my code:
Private Sub CheckForOverlap(myMonth As Messages.MyMonth)
Dim am As New MyMonth()
Dim amCollection As Messages.MyMonthCollection
Dim overlappingMyMonthDate As Boolean = False
Dim sErrorMsg As String = ""
'...non-applicable code omitted
Dim query = From s In amCollection _
Let s1 As MyMonth = CType(s, MyMonth) _
Where s1.AttendanceMonthID <> attendanceMonth.AttendanceMonthID And _
(CDate(attendanceMonth.StartDate) < CDate(s1.StartDate) And CDate(attendanceMonth.EndDate) > CDate(s1.EndDate)) _
Select s1
If query.Count > 0 Then
sErrorMsg = "Dates entered surround another entry"
End If
If overlappingMyMonthDate Then
Throw New Exception(sErrorMsg)
End If
End Sub
End Class
It all came down a LINQ query.
Do you need to do it in code or would SQL be an option? If the data is in a database, you could use the following query to check for overlaps.
SELECT COUNT(*)
FROM Table1
WHERE Table1.StartDate < 'endCheckDate'
AND Table1.EndDate > 'startCheckDate'
This will return a count of the number of overlaps found. 'endCheckDate' and 'startCheckDate' are your new query values (in date format). If your data is in a object collection in memory, then you could use LINQ. If you need help with a LINQ statement, let me know.