Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error In Passing Default Values When New Record Is Created 2

Status
Not open for further replies.

cstuart79

Technical User
Nov 2, 2009
171
US
I have created a pop-up which is supposed to have default values passed on from its originating control. It seems to work properly when a record already exists, but does not pass values when a new record has been added. I know that I need to tweek my code to be more specific about where the default values are coming from but I also may be missing something else to allow new records to function properly. The code that I am using is as follows:

Private Sub Form_Load()
Dim bb As String
bb = SESSIONS.Port
[SESSIONS SOURCES].Port.DefaultValue = Val(bb)
Dim cc As String
cc = SESSIONS.[Session ID]
[SESSIONS SOURCES].Session_ID.DefaultValue = Val(cc)
Dim dd As String
dd = SESSIONS.[Sender Comp ID]
[SESSIONS SOURCES].[Sender Comp ID].DefaultValue = """" & dd & """"
End Sub

Private Sub btMultiple_Sources_Click()
Dim strWhere As String
strWhere = "[Session ID]=" & Me.Session_ID
DoCmd.OpenForm "SESSIONS SOURCES", , , strWhere, OpenArgs:="[Port]" & "[Sender Comp ID]" & "[Session ID]=" & Me.Session_ID
End Sub

Attempting to provide where Port, Session ID, or Sender Comp ID are coming from. Receiving an error "Object required".

Control "Port" is on subform "SESSIONS". Trying to pass this to control "Port" on subform "SESSIONS SOURCES".

Control "Sender Comp ID" is on subform "SESSIONS". Trying to pass this to control "Sender Comp ID" on subform "SESSIONS SOURCES".

Control "Session ID" is on subform "SESSIONS". Trying to pass this to control "Session ID" on subform "SESSIONS SOURCES".
 
There are 2 issues though:
1. even the SessionID is not being passed if a new record(therefore a new SessionID) is created just prior to opening up the pop-up
2. i also want the SenderCompID and Port to be passed
 
Replace this:
DoCmd.OpenForm "SESSIONS SOURCES", , , strWhere, OpenArgs:="[Port]" & "[Sender Comp ID]" & "[Session ID]=" & Me.Session_ID
with this:
DoCmd.OpenForm FormName:="SESSIONS SOURCES", WhereCondition:=strWhere, OpenArgs:=Me!Session_ID & ";" & Me!Port & ";" Me![Sender Comp ID]

Then, the Load event procedure of SESSIONS SOURCES:
Code:
Private Sub Form_Load()
Dim dv
dv = Split(Me.OpenArgs, ";", 3)
If UBound(dv) = 2 Then
  Me!Session_ID.DefaultValue = Val(dv(0))
  Me!Port.DefaultValue = Val(dv(1))
  Me![Sender Comp ID].DefaultValue = """" & dv(2) & """"
End If
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
tried your suggestion but get an error "expected end of statement" with regards to the DoCmd code.
 
Sorry for the typo:
DoCmd.OpenForm FormName:="SESSIONS SOURCES", WhereCondition:=strWhere, OpenArgs:=Me!Session_ID & ";" & Me!Port & ";" [!]&[/!] Me![Sender Comp ID

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top