(Microsoft Access) How to Input multiple new records with 2 out of 5 fields from being reset - ms-access-2007

I am trying to create an input form to input new entry into my table.
Basically, I have a simple table with 5 field. DATE, PERSON, Value x, Value y, Value z.
Every time I finished input a new record, the form reset to blank. I really need the Date and Person Field to keep the previous record value so I dont have to input them again and again. Only reset Value X,Y,Z.
Please help

For the date field, use the AfterUpdate event of the form to set the DefaultValue property as a text expression of the date value:
Me![Date].DefaultValue = "#" & Format(Me![Date].Value, "yyyy\/mm\/dd hh\:nn\:ss") & "#"
Similar for the other fields.

Related

Filter as you type combo box me.recordsource

I can upload a file if someone tells me how.
Need help replicating a filter as you type on a combo box that is being used at the record level. Example: Instead of having an open text box for the prefix (e.g. Mr. Mrs. Ms. Dr.), I'm using a combo box that looks up from a reference table. I want to be able to type the letter "r" in the combo box and have it filter out Ms. and showing the remaining values. Once I make a selection store the selected value in the Name table.
Issue: When I add a new value in Combo4 the other rows above clear out if they don't match the value I just typed into the cell. Something likely with the RowSource in the below formula. Do I have something out of sequence or a flawed formula?
What I think I'm trying to do:
1) If Prefix value populated w/ value in t_Name THEN show the matching value in t_ref_Prefix
2) If Combo4 is Blank / Null THEN then open Combo4 and show all values in t_ref_Prefix so a value can be selected.
3) If user is typing text into Combo4 THEN filter on change using * on both sides of the typed value.
Option Compare Database
Option Explicit
Private Sub Combo4_Change()
'https://stackoverflow.com/questions/48133260/display-records-in-access-db-combobox-on-any-text-typed-by-user
'test number of characters entered - if greater then 0 then assign rowsource
If Len(Me.Combo4.Text) > 0 Then
'set the rowsource to match user search criteria
Me.Combo4.RowSource = "SELECT * FROM t_ref_Prefix WHERE Prefix LIKE '*" & Me.Combo4.Text & "*'"
'show the search in real-time
Me.Combo4.Dropdown
Else
'set to no
Me.Combo4.RowSource = "SELECT t_ref_Prefix.auto, t_ref_Prefix.prefix, t_ref_Prefix.sort FROM _
t_ref_Prefix ORDER BY t_ref_Prefix.sort, t_ref_Prefix.prefix"
End If
End Sub
You need to set
Combo4.AutoExpand = False
This will do it.

i can't fill my gridview vb.net

In my project , i have 2 windows forms and 1 gridview contains 5 columns (name gridv)
I want to fill 4 columns from forms1 and the 5th columun from the forms2
but i can't do it (error in my appli execution )
my code (how to fill the 5th column)
Dim selectrow As Integer = Form1.gridv.CurrentRow.Index ' selectrow mean selected row indice
MessageBox.Show("ligne selectionnée : " & Convert.ToDouble(selectrow))
Form1.gridv.Rows.Add(corp_mail.Text = Form1.gridv.Item(4, selectrow).Value) ' fill the 5th column`
You haven't shown the error but from what information you have given this is what your code is doing:
evaluates if corp_mail.Text is equal to the value of the 5th column of the selected row. This is a true or false, not a string.
Adds (or tries to) a new row to the grid with true or false as the value of the first cell.
If I understand correctly, this is what you want to do:
Form1.gridv.Item(4, selectrow).Value = corp_mail.Text
This will set the value of the 5th column of the selected row.
Although you mention a second grid on another form, not a textbox, so you probably have more work to do. But the idea is the same, instead of the TextBox value get the value from the other grid.

Adding 1 to existing number in a cell based on value of another cell

Alright so I looked through for other solutions but I didn't get anything close enough with my limited knowledge to make it work so I hoping some geniuses here can help.
Basically I am using excel to autoupdate some data based on the value of another cell. A simplified version of my table looks like the below:
ID Step Count
526985 - Step 1 8
123569 + Step 3 3
589745 - Not in AMP 1
589465 + Step 2 5
IDs are unique and always 6 digits (just fyi if that helps anything). There will never be a Step column or count column value without an ID value
I would like to use the change val in vba so it changes as I go along automatically
The goal is for the user to not have to update manually the value in the "Count" column
When the user starts working on the sheet, the "Step" column will be blank and will be selected from a drop down menu but the "Count" and "ID" will be populated already
What I need:
When a value of "+ Step 1", "+ Step 2", "+ Step 3", "+ Step 3 ext", "- Step 2", "- Step 1" is selected in the "Step" column for an ID, I need "+1" added to whatever the current value is in the "count" column
When a value of "- Not in AMP" is selected from the "Step" column, I need the value to be 0 in the "Count" column
There will be other values selectable from the "Step" column which I need to be ignored (Keep the same "Count" column value)
After a step value has been selected in the "Step" column and the "count" column has been updated. I still need to be able to go back and change that value to any other number manually.
I think that's about it. I thought of using formulas which I could do but the issue is where I need to be able to overwrite the value with another, it will delete the formula. I'm open to anything that makes this work though. Thank you in advance!
After you have a Change event you could have some logic to check:
- if user is adding a new value in the correct column, you would load the previous data into a variant to perform the logic that you have given to populate the addition cells
- if not, let the user update the values.

Retrieving both values from a 2 column ComboBox VBA

I have a user form (excel, VBA) where there is a 2 column combobox. When user selects a certain value from the combobox, I want to get the value he selected, and the value associated with the first value (ie. the second column value).
How do I do this? Simply ComboBox1.Value returns the value of the first column. ComboBox1.Value(0) doesn't work.
Use the column property of the combobox. It is 0-based so the first column is column(0) and the second column is column(1).
Me.ComboBox1.Column(1)

Access - Update a field based on other fields

Is there a way for Access to update a field based on the presence of answers in other fields of the same table?
For example, if fields A,B,C,E,F all have information in them (either "yes" or "no"), then column D should be populated with an "x" ; if only A,B,E have information then column G should be populated with an "x"... etc.
Thank you!
Run an Update query. It can be triggered in VBA code based on an OnChange event of a field, or an OnDirty event of the form.
Or, you can just set the control equal to your value based on the same events. You can put code in the OnChange or AfterUpdate event of every control that automatically does that calculation, or have a button that the user would have to press to do the calculation.
It's basically:
If Nz(Len(Me.A)) > 1 and Nz(Len(Me.B)) >1 Then
Me.D = "X"
Me.G = ""
Else
Me.D = ""
Me.G = "X"
EndIf
You obviously have to add more fields, but you get the idea. Make sure you use the Nz function or it will get tripped up if the field has a NULL value in it.