I’m going to keep this simple as possible, I have a ticket system I’m trying to create in MS Access.
I have a dropdown menu that has three options “Open, Assigned, Closed” I have three rows in a table in my database, one for openTime, assignedTime, and closedTime.
My dropdown menu is connected to a row in my table called Status
which is swapped between the three options “Open, Assigned, Closed”. When the ticket is created in my website, it creates an open time so I don’t have to worry about that, but when the user selects assigned and closed I would like it to on change send data to the correct cell.
So if the drop down is swapped from open to assigned it already changes the status cell to “Assigned” in my database but I would also like it to change the assignedTime cell’s data to the exact time and date. Same for closed.
I typically write my code in C# and don’t know VBA at all. this will be done in vba in a Microsoft Access form; how can I do this? Can someone provide suggestions?
I have tried a few different methods, but when I add them to my post it confuses the mods so I’m just looking for your inputs.
EDIT: I think I know how to add the date with
vardtedate = CDate(Format(Me.dtedate.Value, "dd/mm/yyyy"))
and I was think of using and If statement for if it is assigned or closed to direct where to add the data
I just do not know how to add it to my table. Should I use me.requery
and SQL code?
How do If statements work in vba is it like c#?
Can I do
If (dropDown.value == "Assigned") me.requery insert vardtedate into me_alert (assignedTime)
Advertisement
Answer
Not sure why you trying to keep this as short as possible, but THEN include a whole bunch of text and all kinds of extra information about some “web” stuff, since that has next to zero to do with access, and in fact the question!
Your question as stated is: I have a combo box on a form. When I change a value, I want to set another text box (or column) on the form to the current time.
You would use the after update event of the combo box, and the code would be:
me!MyDateTimeColumn = now()
And assuming that the Access form is bound to the table in question? Then you DO NOT want to format the date value, but simply use:
me!MyDateTimeColumn = Date() ' save the date - no time part
or
me!MyDateTimeColumn = Now() ' save the date with time portion
You do not mention if this Access form is connected to a access database, or a sql one?
As in all cases, editing data in a Access form does not issue a save until you: Close the form. Navigate to another record. Force a save of the data with VBA
At this point in time, with the given information, one line of code should suffice.
Edit
It would seem that the question was not clear, and that there is 3 status time fields.
So, the question should have been.
I have a combo box with 3 text values. When I select one of the 3 values, I want to update a corresponding additional set of 3 columns to the current time + date based on 1 of the 3 values selected.
So, in the after update event of the combo box, we could use:
Private Sub Combo2_AfterUpdate() Select Case Me.Combo2 Case "Open" Me!OpenTimeUpDate = Now() Case "Assigned" Me!AssignedTimeUpdate = Now() Case "Closed" Me!CloseTimeUPdate= Now() End Select End Sub
So in above, we assume 3 values (Open, Assigned, Closed), and we assume 3 addtonal columns nameed OpenTimeUpdate, AssignedTimeUpdate, and CloseTimeUpdate