In our continuous form in Access we want to offer a combobox which will show 7 days with the dayname as part of the dropdown.
The combobox is bound to a date field. We can easily populate the combobox in the Form Load event to show the days in ddd dd/MM/yy format and existing dates are happily shown on the form like so:
However if you try and pick from the dropdown you get the error:
The value you entered isn't valid for this field.
Solutions involving an unbound combobox won't work as this is a continuous form.
It's kind of a detail, as the dayname isn't absolutely necessary, and the combo works fine without the dayname. However this is a heavy duty data entry form so optimising for the end user is important and having the daynames will assist him/her.
I recreated the problem and the solution I came up with was to have a combo box where the row source has two columns and you hide the first column using ColumnWidths and the second column is the formatted date value. So when you pick something in the combo box, the value is an unformulated date value which gives no issue.
Populate the combo like so:
Dim i As Integer
For i = 0 To 6
Dim item As Date
item = DateAdd("d", i, weekCommencingDate)
cboTimeDate.AddItem item & ";" & Format(item, "ddd dd/MM/yy")
Next i
Related
I have a table(table Income) with 8 fields for recording Income and Expense.
No: AutoNumber
PL: Income/Expense
Date
Staff_ID
Customer_ID
Payment_Type: Cash, Credit,...
Service
Amount
I create a form with a subform for data input.
cmb_pl, cmb_date, cmb_staffid, cmb_custid, cmb_type, cmb_service, txt_amount
Income 03-Dec-20 1 2 Credit hair_cut $15
After click button Add then this record will run into subform.
Next I input second record which few differences from first record.
cmb_pl, cmb_date, cmb_staffid, cmb_custid, cmb_type, cmb_service, txt_amount
Income 03-Dec-20 1 2 Credit nail_fix $18
In this case, if I lazy to reinput the data then I just only double click on those fields then data from previous record (first record) will come itself. And for those which not double click then I can insert the value from the combo or textbox.
So, what is your direction for making this works?
Million thanks for your wonderful support!
Use VBA in each control's BeforeUpdate or AfterUpdate event to set its DefaultValue property. Value will carry forward to each new record until user inputs a different value. No double click required.
Me.YourControlName.DefaultValue = """" & Me.YourControlName.Value & """"
This syntax is valid for Text, Number, DateTime and Boolean Datatypes.
I'm working on an Access 2007 database and I'm having a problem with a query.
I have a table named Vehicles, which contains data such as ID, license plate and fuel type for each vehicle in it.
I'm trying to make a query which will populate a combobox in a Form with each vehicle's fuel type, based on the license plate chosen by the user beforehand.
The thing is, we have some some cars that work with two types of fuel and I cant' find a way to display them separately in the combobox.
So far it kinda works, code follows:
CheckDiesel: IIf([Diesel]="Yes";"Diesel";IIf([Gasoline] AND [Ethanol]="Yes";"Gasoline"+ "Ethanol";IIf([Ethanol]="Yes";"Ethanol";IIf([Gasoline]="Yes";"Gasoline";""))))
If you look at the second IIf, I have a condition for a bi-fuel car. I want to display Gasoline and Ethanol separately, each one in a row.
I've tried using "&Chr(10) Chr(13)&" and "\r\n" but I had no success so far.
Can anyone help me?
Storing multiple pieces of data in a single field rarely ends well. A few options I see
A series of binary fields for gasoline type. So you'd have a True/false for gasoline, ethanol, and diesel. This is easy to show with checkboxes on the form.
If you know there will only be certain combinations, like if there will not be a 'diesel and ethanol' without gasoline, you can build it as a single value combobox.
You will probably need some VBA to do what you need to do. Try something like this:
Dim R as String
R=""
if (Me.Diesel) then R = R & "Diesel;"
if (Me.Gasoline) then R = R & "Gasoline;"
… {add any other types of fuel}
Me.MyComboBox.Rowsource = R
Me.MyComboBox.Requery
This can be added tot he form's OnCurrent event so it will update the combo box every time a new record is displayed.
If your form does not include the various fuel types as fields, either add them as hidden fields or use DLookup to read them off the table.
Hy all ,
I'm making an access 2013 databases application , for my work place with the scope to generate automatically some documents based on some combo box selections.
So in order , to be much more specific , the main form have :
one combo-box selection for truck number (cboNr_Auto) which reads from table "Advanced Conditional List" and fill auto text boxes for displaying name of driver , license number , etc... ( working well with afterUpdate event)
one combo-box selection for code of trash (cboCod_Deseu) which reads from table "Categorie_Deseuri" and display the name of the trash in text-box "txtDenumire_Deseu" ...(not working)
date pickers for loading and unloading dates- working well
text box for manual entry of weight - working well
My questions are next :
how can i make my combo-box selection "cboCod_Deseu" to display values in text-box from the table "Categorie_Deseuri" in my main form ?
how can i generate an report based on my combo-box selections , date pickers and manual entry for the weight field via a pushbutton?
Thanks
let say you have combobox with a recodsource and this recodsource returns 3 column.
Now if you want to set the textbox based on the selcted value of combobox than you can set the textbox controlsurce as below.
=[Combo0].[column](1)
'Combo0' is the name of combobox.
For report based on the different criteria.
first of all create a query for the report and change this query based on your criteria.
Below is the small example how you can acheive this.
Dim query_1 as string
query_1 = "Select * from Table1 where DATE = #yourdate#"
CurrentDb.QueryDefs("Report_Query").sql = query_1
Report_Query is the name of the query which you have saved earlier. open the report based on this.
The problem I am having is displaying the correct information in a combobox on an unbound form when a users views/edits data.
The table that populates the combobox:
tblLocation
idLocation
Location
Location Description
In the tblPerson table, there is a FK field called idLocation. I have a form that allows a user to pick a person from a listbox and displays the information in textboxes and comboboxes.
The combobox is setup with these items:
idLocation <--- column width set to 0
Location
The problem I am having is having the data show up correctly in the comobox when I view/edit a new person.
When a person is selected from a ListBox, the information from tblPerson should display in textboxes and comboboxes. The textboxes work just fine. However, I'm struggling with the comboboxes. Keep in mind all of the fields
My research finds only two methods on solving this problem:
DLOOKUP
Manual check and set
If I use the DLOOKUP method:
cmbLocation = (DLookup("Location", "tblLocation", "idLocation=" & .Fields("idLocation")))
The problem is that msgBox cmbLocation will display the text and not the FK. If the user tries to edit the data, but makes no changes, it will try to save the text and not the FK.
I found a manual way that does work, but I'm not sure it is the best approach:
For i = 0 To (cmbLocation.ListCount - 1)
If Val(cmbLocation.Column(0, i)) = Val(.Fields("idLocation").Value) Then
cmbLocation = cmbLocation.ItemData(i)
Exit For
End If
Next
Again, this works - but I have to think that I'm doing something wrong - probably something obvious.
Is there a better way to do this?
you can dynamically change which data is displayed in a combobox. in your scenario, i suggest you use the OnClick event of the listbox (once the person is selected). Add the following code:
YourComboBoxName.RowSource = "SELECT * FROM tblLocation WHERE idLocation=" & FK
If after clicking on a person, the data doesn't change in the combobox, you may need a Me.Refresh
Base the form on a query that left joins in the location column.
Then that field when bound to a text box will will display automatic and without any code. And better is if the actual location value changes, then no update code etc. is required. In fact this is the whole beauty of a relational database!
MS Access Scenario:
I am using a form (we'll call it the select_contract form) and a subform (we'll call it the employee_allocations_by_contract subform).
The select_contract form:
Is unbound.
Contains a combobox that allows the user to select a contract id.
The employee_allocations_by_contract subform:
Is a continuous form.
Is bound to a table (which I'll call the hours_allocation table) that contains the number of hours that each employee is allocated to each contract.
Binds only one field, the employee_id field, to the hours_allocation table. The row source for this field is a query that returns the ids of employees that have hours allocated to the contract that the user has selected in the select_contract form.
Contains twelve other, unbound fields, one for each month of the year. These fields are intended to display the number of hours allocated to the employee listed in the employee_id field for each month of the year.
The Problem: In order to display the number of hours by month that are allocated to each employee listed on the employee_allocations_by_contract subform, the queries for each month field need access to the employee_id field of the row on which they appear. I haven't been able to figure out how to reference this field. Because the employee_allocations_by_contract subform is a continuous form, a reference to the the employee_id field name appears to reference each row on the form.
I have searched several forums and have found related continuous form issues, but nothing that clearly addresses this problem. Any thoughts?
Well, you could build a sub-query for each of the month columns you need that total for.
Something like:
Select id, employee_ID, bla, bla, bla,
(select sum(hours) where month = 1 and year = 2010 and
employee_id = ehours.Employee_id from tblProjectHours)
as month1,
(select sum(hours) where month = 2 and year = 2010 and
employee_id = ehours.Employee_id from tblProjectHours)
as month2,
(select sum(hours) where month = 3 and year = 2010 and
employee_id = ehours.Employee_id from tblProjectHours)
as month3
etc. for each column needed
from ehours
Note I used month and year as columns and you likely have to use month([SomeDate]) = 2 and year([SomeDate]) = 2010, but you get the idea.
Also, while you can't address each row and stuff a value into that un-bound text box, you CAN in fact bind the text box to a function that returns the value/expression you need.
txtBoxMonth1 txtboxMonth2 etc.
=MyMonth(1,[employee_id]) =MyMonth(2,[Employee_id])
And, then in the form, you have a public function called
Public Function MyMonth(intMonth as interger, lngEMPID as long) as long
' code here to get total based on employee id and month
End Funciton
So, you can bind a function to those text boxes, and the current row emp ID can thus drive what each text box displays. Just remember that this function should have all of the data pre-processed, and you don't want to have to re-run and re-load the data for each function call as that will be FAR too slow. However, I have used this approach to much success. So, each row of the form only has one real column (empID), the rest of the columns are derived from text boxes bound to the public function as per above with the month being passed along with the emp id to return the value for that column.
So, above is two possible approaches I used with success.
An unbound control on a continuous form can only refer to the record that has the focus. There fore, if data is entered into an unbound control, you will see the same data for every record in the continuous form.
You cannot reference controls "individually" ("at the line level") in a MS Access continuous form.
Your only solution here is to bound these controls to an underlying recordset\recordsource where corresponding fields hold the values to be displayed.
For example, if you want to display a time period as the difference between a "date in" and a "date out", your recordset\recorsource could be something like:
select id_person,dateIn,dateOut,dateDiff(xx,dateOut, dateIn) as timeIn from ...
Then your time calculation control has to be bound to the 'timeIn' field of the recordset.
(*) please check the dateDiff arguments. I do not have any help available here ..