Modules & VBA :: How To Get Day Name Of Date
Feb 23, 2014
I want to know the day name of a date. I am getting type mismatch 13 for this line
PrintingDateDayName = WeekdayName(Weekday(PrintingDate))
So this code is not right. This is my full code
Dim RegisterDate As Date
Dim PrintingDate As Date
Dim PrintingDateDayName As Date
RegisterDate = Me.txt_register_date
PrintingDate = RegisterDate + 180
PrintingDateDayName = WeekdayName(Weekday(PrintingDate))
If PrintingDateDayName = vbSunday Then
MSG1 = MsgBox("It's Sunday", vbOKOnly + vbInformation + vbMsgBoxRtlReading, "Clients Database")
Else
MSG1 = MsgBox("It's Not Sunday", vbOKOnly + vbInformation + vbMsgBoxRtlReading, "Clients Database")
End If
View Replies
ADVERTISEMENT
Oct 24, 2013
I'm trying to get my "IncidentDate" field to autopopulate two other date fields to a few days from the "IncidentDate". The other two date fields are "ContainDueDate" and "RootDueDate". I'm trying to accomplish this on my "Test CAP Form"
I tried using the following in the BeforeUpdate of "ContainDueDate" and received a complier error: expected =
Code : DateAdd(d,2,[IncidentDate])
so I removed the parenthesis and nothing happened
Code : DateAdd d,2,[IncidentDate]
I even tried redoing it in the AfterUpdate of "IncidentDate" and nothing happened either
Code : DateAdd d,2,[ContainDueDate]
I'm not sure if I'm even using the right function to get what I want.
View 4 Replies
View Related
Mar 12, 2014
I have a form with Date of Death (DOD) field. I would like update DOD from a table dbo_patient into Z_Patients table.
I have set the datatype as Date/Time in the form for Date of Death.
Code:
Private Sub Update_DOD()
Dim rcMain As New ADODB.Recordset, rcLocalDOD As New ADODB.Recordset
Dim DOD As String
rcMain.Open "select distinct PatientKey from Z_Patients", CurrentProject.Connection
[Code] ....
However I am getting some error Run-time error '-2147217913 Date type mismatch in criteria expression in section below.
Code:
CurrentProject.Connection.Execute "update Z_MAIN_Processed_Patients set DateOfDeath = '" & rcLocalDOD!date_of_death & "' where PatientKey = " & !PatientKey
View 5 Replies
View Related
Dec 9, 2014
How can I add 7 days in todays date to store target date in the table?
Code:
ssql = "Insert into tblUpdate([Update_ID],[Date],Username,Status,Target_Date) values('" & j & "',#" & Format(Date, "mm/dd/yyyy") & "#,'" & k & "','Open')"
CurrentDb.Execute ssql, dbFailOnError
View 3 Replies
View Related
Jan 22, 2014
I have some code that filters job raised I have 2 text box's txtdatestart and txtenddate after entering. date range between the too text boxs it shows me all job raised with in the period.i have entered what I would like is filter it again by client field using combo box cboclient so if the user enter's client name in cboclient combo box and date range in txtdatestart and txtenddate it will only show jobs raised with in the date range of the client enter in the combo box but if the combo box is empty show.
Code:
Private Sub cmdPreview_Click()
'On Error GoTo Err_Handler 'Remove the single quote from start of this line once you have it working.
Dim strReport As String
Dim strDateField As String
Dim strWhere As String
Dim lngView As Long
Const strcJetDate = "#mm/dd/yyyy#" 'Do NOT change it to match your local settings.
[code]....
View 6 Replies
View Related
Jan 27, 2015
I want to find out the last 6 months date from todays date. So as todays date is 27th january 2015 so the code should give me the date which is 6 months back from todays date so it will be something like 27th July 2014.
View 1 Replies
View Related
Jan 13, 2015
I have attached a sample database. Basically I want to have some lines of code that generate the result table, which is tbl_readmit_result.
As you can see, the difference is the addition of a new column called re_admit_status.
Rule is:
Status = "y" when the admission date, compared to the previous discharge is less than 7 days, otherwise "n", for the same pt_id. You cannot compare the two dates on different pt_ids.
Is there a way that this can be done automatically without having to go through the record manually?
View 1 Replies
View Related
Nov 14, 2013
There are a variety of date functions but I specifically want to show the date or the first working day after the 25th of each month.
Eg:
if 25 Oct is a Monday then result = 25 Oct
if 25 Oct is a Sunday then result = 26 Oct
View 4 Replies
View Related
May 29, 2014
I have a form who's control source is a query which displays dates that personnel and equipment are mobilized.For invoicing on a weekly basis i need to display the number of days within the week that these are on hire.The mobilization and demobilization dates may be well outwith the weeks dates or may be within the week though.
For example MobDate 20/03/2014, DeMobDate 13/06/2014 but the week is this week.or Mobdate 27/05/2014, DeMobDate Today 30/05/2014
I need to display the actual dates if within the current week or display the first day of the current week and the last day of the current week if the mobilization and demobilization dates are outwith the current weeks dates?I have created two unbound textboxes MobTextBox and DeMobTextBox and am trying to use the code below to insert what i described above.Once i have the dates inserted i have a third textbox with the ControlSource set to =DateDiff("d",[MobTextBox],[DeMobTextBox])
Dim MobDate As Date
Dim DeMobDate As Date
Me.MobDate.SetFocus
If Me.MobDate.Text > (Date - 7) Then
Me.MobTextBox.Text = Me.MobDate.Text
[code]...
View 5 Replies
View Related
Dec 22, 2013
I want set two dates by vba but i don't no how to do it ... for more understand look the simple example
If Date = #12/20/2013# Then
MsgBox "Wrong", vbExclamation, "attention"
End If
But I want set date between two days for example like that
If Date = between #12/20/2013# and #12/20/2014# Then
MsgBox "Wrong", vbExclamation, "attention"
End If
View 3 Replies
View Related
Feb 27, 2014
I want to add a string as year to a date.
Somehow it doesn't work out. It should extract all records with Valid_from = 01.01.2013 and valid_to = 31.12.2013. The Year assignment works.
Code:
Public Sub BEN()
Dim strSQL As String
Dim t As Date, s As Date
DoCmd.SetWarnings False
Year = Right(pricedate, 4)
t = 1 / 1 / " & Year & "
s = 12 / 31 / " & Year & "
strSQL = "SELECT TRANSFER_PRICES.* INTO [TEMP] " & _
" FROM TRANSFER_PRICES " & _
" Where [Valid_from] = " & Format(t, "#mm/dd/yyyy#") & _
" AND [Valid_to] = " & Format(s, "#mm/dd/yyyy#")
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
End Sub
View 3 Replies
View Related
Jan 24, 2014
I have the following code that updates the end date to be the same as the start date after the user tabs out of the start date. Instead of making it the same date, I want it to be six days later. How do I add that?
For example, user enters 11/10/13 in the start date. I want the end date to automatically update to 11/16/2013.
Code:
Private Sub StartDate_AfterUpdate()
Dim datDate As Date
If Nz(Me!StartDate.Value, #1/1/1900#) = #1/1/1900# Then
'The user removed the START data as criterion, so remove the END date.
Me!EndDate.Value = Null
[Code] ....
View 2 Replies
View Related
Jul 11, 2015
Im a relative novice with access VBA, and I'm really struggling with using Dcount with date variable. All I want to do is count if a certain date appears in a table. Here is the extract from my code:
Dim WorkoutDate as Date
Dim datecount as integer
datecount = DCount("[WorkOut Date]", "tblworkoutlogs", "[workout date]= " & WorkoutDate)
Whatever dates are in tblworkoutlogs, datecount is still = 0...I've trawled the net and tried many variations of the code but no success!if I change all the date formats to strings in the code and the tables, it works so I know i'm looking in the correct place.
View 5 Replies
View Related
Mar 17, 2015
how shall i define my new Date or numbers.Now "yyyyXX" this is my date "y" is year 4 digits and "XX" is my problem 2 digits. I ll give an example,
(XX = 01....36) XX can be max 36 and min 01 of course. f. Exp. 201436 and next number shall be 201501.
the biggest problem is different of these number with basic math 201501-201436= 65 but for me it should be 01... The Question is; How can define these ??
View 8 Replies
View Related
Mar 3, 2015
i am having an issue with sql in vba using a variable for a date time field.
i know you identify date variables with #
i know you identify text variables with '
But now i have a date time field that is set to date but when i run the sql it does not find a match. i have confirmed that both rec and ercd match.
Also, when i change the table to text, i am able to match with single quote but i would like to keep the table as date if i can.
Below is the sql statement in question
isql = "SELECT * FROM Table1 WHERE from = '" & nm & "' AND rec = #" & ercd & "# AND sub = '" & esub & "'"
View 5 Replies
View Related
Jul 3, 2013
I have come across a weird event from the 1st July.
I have a form that inputs dates into the table.......nothing special.......
Form is totally unbound and the insertion to the table is done via DoCmd.RunSQL Insert every thing has been fine until the 1st of July at this point it started saving the date into the table in American format 07/02/2013 instead of UK 02/07/2013 There have been no changes to the database at all to give me a reason why this has happened.
The Table fields are set to Date Fields.
The SQL Insert was set to Date ( #" & DATE & "# )
The date displayed on the form is in the correct format to get around this I have set the insert of the date as a string ( '" & DATE & "' ) AND how can i reformat the dates that are incorrectly inserted to the correct format as they include the date and time 07/02/2012 11:11:47
There is about 1000 lines so manual change will be a nightmare.
View 8 Replies
View Related
Jan 28, 2014
I want to create a table via SQL. This table should contain records that begin after a specified date.
Something is wrong with this syntax.
Code:
Sub TEST()
Dim t As Date
t = 1 / 3 / 2014
DoCmd.RunSQL "SELECT TRP.Customer, TRP.Material, TRP.Product_Class, TRP.TRP as Price, TRP.Valid_from, " & _
" TRP.Valid_to INTO [New_Prices] " & _
" FROM TRP " & _
" WHERE (((TRP.Customer)= 1223) AND ((TRP.Valid_from)>#t#))"
End Sub
View 14 Replies
View Related
Dec 4, 2014
I use textboxes to limit the time periods for report the defaults are set to first and last day of previous month I'd like to add a button that would set you a month back/forward, but I'm stuck on how to change values to correspond to first/last day ofprevious month
this is my onload code
Quote:
LastDay = DateSerial(Year(Date), Month(Date), 0)
FirstDay = LastDay - Day(LastDay) + 1
Me.tdat1 = FirstDay
Me.tdat2 = LastDay
View 3 Replies
View Related
Jan 27, 2014
I have an Excel workbook which I use to extract data from an Access database using VBA. A requirement has popped up to show things from the last week. Unfortunately, I can't just use a Date()-7 query in Access as the start point might be different, so it needs to be based on seven days prior to a date field in Excel.
So, I have a cell in Excel with a date, in this case "16/01/2014". I want to then use that date in my query to say "greater than 8 days prior to to this date". The field is formatted as a date and the variable (DatafileDate) taken from this field and passed to the function is a Date. In my Select query I then have this line to select the top 5 marked as UK accounts in this case:
Code:
SearchText = "SELECT TOP 5 * FROM `" & TableName & "` WHERE `" & TableName & "`.`Account`='UK' AND `" AND `" & TableName & "`.`Close Date` > #" & DatafileDate & "#"
Code:
#" & DatafileDate & "#" -8
Should mention that the TableName stuff is so the name of the table can be set elsewhere. "Close Date" is the column in my Access query I need to filter on.
View 2 Replies
View Related
Mar 19, 2014
In my Access form, users update 4 checkboxs when their work is completed, when this 4 boxed checked then the 5th checkbox will check automatically using afterupdate. Now i have added the 6 the column with date completed, here i want the date to be updated automatically when the 5th column is checked automatically. how to do it?
View 10 Replies
View Related
Mar 21, 2015
I have a set of combo filters that filter one after the other as follows –
Code:
Private Sub cboCity_AfterUpdate()
If Nz(Me.cboCity.Text) = "" Then
Me.Form.Filter = ""
Me.FilterOn = False
[code]...
and so on to filter down so the user can work with what they filter, my question is how can I add on a filter that filters between dates? and second I was hoping that I could program the filters so that they could be changed individually/randomly as to filtering one after the other and then clearing to restart the filtering again if that makes sense. I have tried using this, but it doesn’t work ‘Bad Command’
Code:
Me.Form.Filter=”StartDate =#” & Format(Me.txtStartDate, “mm/dd/yyyy”) & “#”
And
Code:
Me.Form.Filter=”EndDate =#” & Format(Me.txtEndDate, “mm/dd/yyyy”) & “#”
View 4 Replies
View Related
Mar 5, 2014
At the moment I have a form (InputFrm) for operators to enter production processes into the system. Each one of these has a certain weight which the operators enter and it all stores in InputTbl, which works great.
However I am trying to have a running total of the kilograms inputted on each day displaying when a new record is opened. To do this I have created a query (DailyDataQry) which provides me a running sum of how much input has gone through the process, and I can clearly see the data in this query.
I am attempting to have a text box in the upper right of my form which displays this number as after a certain weight of input the operators are needed to perform checks.
This is the code I have at the moment in the control source of a text box (DailyInputTotalTxt), but it is just returning a blank:
Code:
=DLookUp("[Total Input]","DailyDataQry","[Work Date] = #" & [Forms]![InputFrm]![WorkDateAtxt] & "#")
The work date is generated automatically when the new record is created by having Date() in the default value of the work date (WorkDateAtxt) on the form.
Is there any way which I can use this value to lookup the current total of input contained within DailyDataQry?
View 3 Replies
View Related
Feb 5, 2014
I have a main form which employees use to report their bi-weekly time. The main form is automatically assigned a [RecordID] and the employee must select their [Profile] from a combo box. This main form contains (2) sub-forms. Both sub-forms use the same data source table.The first sub-form is visible in the body of the main form and linked by the [RecordID] and employee [Profile]. The employee enters each date worked and hours for the reporting period.
The second sub-form is hidden and linked to the main form by the employee [Profile], basically keeping a running ledger of all the dates and hours reported by the employee. What I would like to do is have a message box appear if the employee mistakenly enters date that has already been reported.
View 11 Replies
View Related
Mar 6, 2015
I'm trying reference a dcount on two fields, one is a string and works fine, the other is on a date which does not.
I've investigated the problem and found a couple of references to making sure I use a # symbol to reference the date but I think the thing that's throwing the comparison out is that the date field stores time as well, even if you can't see it?
Code:
MsgBox DCount("*", "[healthcheck]", "[check_date]=#" & Format([Forms]![MAINTENANCE_FRM]![MAINTENANCE_DETAIL_TBL subform].[Form]![FIRST_HEALTH]) & "#")
I thought should count the records in the healthcheck table that match the check_date field against the first_health field on the current form, but I keep getting a 0 count even though the dates seem to match.
View 6 Replies
View Related
Feb 16, 2014
I want to select a subset of table called TRP. It should extract me all records
which got the property Valid to date < enddate.
enddate is a date selected by the user in a form .
Somehow it doesn't recognize the enddate in the following :
Code:
Public Sub test()
DoCmd.SetWarnings False
DoCmd.RunSQL "SELECT TRP.* INTO [TEST] " & _
" FROM TRP " & _
" Where TRP.[Valid to] < enddate"
DoCmd.SetWarnings True
End Sub
View 14 Replies
View Related
Mar 5, 2015
I am writing code in excel VbA that will fetch data from Access table.
04/03/2015 means 4th March 2015 so if I write the sql query as below then it doesn't pull anything from access table.
Code:
strsql = "SELECT DISTINCT printpoolno FROM tblmaster where username='" & Application.UserName & "' AND Date1=#" & Format("04/03/2015", "mm/dd/yyyy") & "#"
MsgBox strsql
What shall I do?
View 2 Replies
View Related