Using a date field as OpenArgs

  • Thread starter Thread starter tigger
  • Start date Start date
T

tigger

Help!

I am trying to open a new form (and a new record) and want to pass the Audit
ID and Actual Date from the Audit Details form to the Audit ID and Date
Raised fields in the NCR Details form.

The Audit ID works beautifully but the date is being displayed as a time.
The formatting of all underlying tables and the control itself is Medium Date
with no input masks.

Can anyone explain the problem?

Thanks, my code is below.

+++++frmAuditDetails:Code+++++
Dim stDocName As String
stDocName = "frmNCRDetails"

'Load the data entry form and autopopulate the Audit ID field
DoCmd.OpenForm stDocName, acNormal, , , acFormAdd, acDialog, _
txtAuditID.Value & ";" & txtActualDate.Value

'Requery the main form when the data has been entered
Forms!frmAuditDetails.subfrmNCRs.Requery

+++++frmNCRDetails:Code+++++

Dim lngAuditID As Long
Dim dteDateRaised as Date

If Not IsNull(Me.OpenArgs) Then
lngAuditID = Left(OpenArgs, InStr(OpenArgs, ";") - 1)
dteDateRaised = Mid(OpenArgs, InStr(OpenArgs, ";") + 1)

Me.txtAuditID.DefaultValue = lngAuditID
Me.txtDateRaised.DefaultValue = dteDateRaised
End If
 
I believe what Alex is suggesting is open the form using:

DoCmd.OpenForm stDocName, acNormal, , , acFormAdd, acDialog, _
txtAuditID.Value & ";" & Format(txtActualDate.Value, "\#mm\/dd\/yyyy\#")

and handle the arguments using:

If Not IsNull(Me.OpenArgs) Then
lngAuditID = Left(OpenArgs, InStr(OpenArgs, ";") - 1)
dteDateRaised = CDate(Mid(OpenArgs, InStr(OpenArgs, ";") + 1))

Me.txtAuditID.DefaultValue = lngAuditID
Me.txtDateRaised.DefaultValue = dteDateRaised
End If

You could also try leaving how you're calling it as-is, and changing what's
in the called form to

If Not IsNull(Me.OpenArgs) Then
lngAuditID = Left(OpenArgs, InStr(OpenArgs, ";") - 1)
dteDateRaised = CDate(Mid(OpenArgs, InStr(OpenArgs, ";") + 1))

Me.txtAuditID.DefaultValue = lngAuditID
Me.txtDateRaised.DefaultValue = Format(dteDateRaised,
"\#mm\/dd\/yyyy\#")
End If
 
Back
Top