UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Entering Date, Access 2016    
 
   
davideyles
post Sep 9 2019, 02:33 AM
Post#1



Posts: 213
Joined: 13-April 03
From: Cornwall, UK


Hi All
I've recorded and tweaked a simple macro to clear a form and the get various input boxes to re- enter new data. I am however struggling with the date input part. Even though my regional settings are UK, the date is entered in the format mm/dd/yy. How can I fix this??


David




Sub Clear_and_renter()
'
' Clear_and_renter Macro
'

'
Application.ScreenUpdating = False
Range("D5:D7").Select
Selection.ClearContents
Range("D9").Select
Selection.ClearContents
Range("F8").Select
Selection.ClearContents
Range("M3:M4").Select
Selection.ClearContents

Range("M3").Select
ActiveCell.FormulaR1C1 = InputBox("Enter Fresh Sample Hours", Default:=48)
Range("M4").Select
ActiveCell.FormulaR1C1 = InputBox("Enter Frozen Sample Hours", Default:=54)
Range("D5").Select
ActiveCell.FormulaR1C1 = InputBox("Enter Client Name")
Range("D6").Select
ActiveCell.FormulaR1C1 = InputBox("Enter Number of Donors")
Range("D7").Select
ActiveCell.FormulaR1C1 = InputBox("Enter Breed")
Range("D9").Select
ActiveCell.FormulaR1C1 = InputBox("Enter Flushing and Transfer Date", Default:="dd/mm/yy")
Range("F8").Select
ActiveCell.FormulaR1C1 = InputBox("Enter Treatment Time", Default:="hh:mm")
Application.ScreenUpdating = True

End Sub
Go to the top of the page
 
arnelgp
post Sep 9 2019, 02:51 AM
Post#2



Posts: 1,510
Joined: 2-April 09
From: somewhere out there...


you format the cells using Custom format: dd/mm/yy

--------------------
Never stop learning, because life never stops teaching.
Go to the top of the page
 
davideyles
post Sep 9 2019, 04:02 AM
Post#3



Posts: 213
Joined: 13-April 03
From: Cornwall, UK


Hi
The cell is formatted to dd/mm/yy, but when I enter the date 05/09/19 (or even 5/9/19) it enters into the cell 09/05/19 which is mm/dd/yy!!


David
Go to the top of the page
 
arnelgp
post Sep 9 2019, 04:34 AM
Post#4



Posts: 1,510
Joined: 2-April 09
From: somewhere out there...


inputbox returns string.
after inputting the date on the box, parse the string
and convert it to proper date:
CODE
Dim sDate As String
Dim var As Variant
sDate = InputBox("Enter Flushing and Transfer Date", Default:="dd/mm/yy")
'check if date has entered
If IsDate(sDate) Then
   var = Split(sDate, "/")
   ActiveCell.FormulaR1C1 = DateSerial(Val(var(2)), Val(var(1)), Val(var(0)))
End If

This post has been edited by arnelgp: Sep 9 2019, 04:35 AM

--------------------
Never stop learning, because life never stops teaching.
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    9th December 2019 - 04:48 AM