AlexDobbin
New Member
- Joined
- Apr 13, 2015
- Messages
- 4
Hi all,
I'm very new to VBA and excel development, so please take that into consideration as you read on.
I'm trying to create a work form for a database that (should) collect various information in comboboxes, including the date, the weekday, and the month... Note: most of the time, the data will be inserted the day after it's been collected. So, I wanted to create one combobox for the date, one for the weekday, and one for the month, because I want columns for each of these in the database (If this is not necessary/efficient, please help! ) .
Here's what I've got so far:
Problem #1: Right now, I am getting the date values from the list DateList in the worksheet LookupList...is there a better way of doing this?
Problem #2: When the user form is run, the correct date and format shows up. However, if I change the date, the dropdown list in the combobox starts from the initial date in given list...is there anyway to bring the list closer to the current date?
Problem #3: I want the weekday and month values to be directly correlated to the date value discussed above, so hypothetically when the user form is run the correct date, weekday, and month all show up (based on the same date value), then if I change the date, the weekday and month automatically update. Is this possible, if so how?
The reason I want this functionality is so that on a Monday, I can run the work form and it will automatically have Friday's date, weekday, month info as it opens. When I'm done with Friday, I can run it again, switch the date to the Saturday's date (weekday and month automatically update), then repeat for Sunday.
I have tried running the same code for the weekday and month as I have for the date, and they work until the date is changed. Once the date is changed, I have to manually change the weekday, which leads to format change, and same for month, which all leads to
Again, I am very new to vba and don't know much about it all and appreciate any/all help!
Thanks in advance!
/Alex
I'm very new to VBA and excel development, so please take that into consideration as you read on.
I'm trying to create a work form for a database that (should) collect various information in comboboxes, including the date, the weekday, and the month... Note: most of the time, the data will be inserted the day after it's been collected. So, I wanted to create one combobox for the date, one for the weekday, and one for the month, because I want columns for each of these in the database (If this is not necessary/efficient, please help! ) .
Here's what I've got so far:
Code:
'worksheet setup
Dim ws As Worksheet
Set ws = Worksheets("LookupList")
'Date dropdown setup
Dim cDateToday As Range
For Each cDateToday In ws.Range("DateList")
With Me.cboDate
.AddItem cDateToday.Value
End With
Next cDateToday
'If today is Monday, then set date to last friday, if any other weekday, set it to day before that
If Weekday(Date - 1) <> 2 Then
Me.cboDate.Value = Format(DateAdd("D", -Weekday(Date) - 1, Date), "Medium Date")
Else
Me.cboDate.Value = Format(Date - 1, "Medium Date")
End If
Problem #1: Right now, I am getting the date values from the list DateList in the worksheet LookupList...is there a better way of doing this?
Problem #2: When the user form is run, the correct date and format shows up. However, if I change the date, the dropdown list in the combobox starts from the initial date in given list...is there anyway to bring the list closer to the current date?
Problem #3: I want the weekday and month values to be directly correlated to the date value discussed above, so hypothetically when the user form is run the correct date, weekday, and month all show up (based on the same date value), then if I change the date, the weekday and month automatically update. Is this possible, if so how?
The reason I want this functionality is so that on a Monday, I can run the work form and it will automatically have Friday's date, weekday, month info as it opens. When I'm done with Friday, I can run it again, switch the date to the Saturday's date (weekday and month automatically update), then repeat for Sunday.
I have tried running the same code for the weekday and month as I have for the date, and they work until the date is changed. Once the date is changed, I have to manually change the weekday, which leads to format change, and same for month, which all leads to
Again, I am very new to vba and don't know much about it all and appreciate any/all help!
Thanks in advance!
/Alex