Passing values

tklingborg

New Member
Joined
Jan 30, 2016
Messages
3
Hi I'm trying to pass some values from a form where someone can select a customer. I'm trying to make it possible to select a customer and pass the information in that form to another form.

This is what I've got so far, but I can't get it to work.

Code to open customer select form and pass if it is as sender I want to import the customer:
Code:
Private Sub cmdSearchConsignor_Click()
DoCmd.OpenForm FormName:="frmCustomerSelect", View:=acNormal, Datamode:=acFormReadOnly, WindowMode:=acDialog
TempVars.Add "TempSendRecieve", "Consignor"
End Sub

Code to open customer select form and pass if it is as recipient I want to import the customer:
Code:
Private Sub cmdSearchConsignee_Click()
DoCmd.OpenForm FormName:="frmCustomerSelect", View:=acNormal, Datamode:=acFormReadOnly, WindowMode:=acDialog
TempVars.Add "TempSendRecieve", "Consignee"
End Sub

Code to pass information from customer select form to waybill form based on wether it's for sender or reciever:
Code:
Private Sub cmdSelect_Click()
If Not IsNull(TempVars!TempSendRecieve) Then
    If TempVars!TempSendRecieve = "Consignor" Then
        TempVars.Add "tempConsignorName", Me.txtCustomerName.Value
        TempVars.Add "tempConsignorAddress", Me.txtAddress1.Value
        TempVars.Add "tempConsignorAddress2", Me.txtAddress2.Value
        TempVars.Add "tempConsignorZIP", Me.txtZIP.Value
        TempVars.Add "tempConsignorCity", Me.txtCity.Value
        TempVars.Add "tempConsignor_Customer_Number", Me.txtCustomerNumber.Value
        TempVars.Add "tempContract_Of_Carriage", Me.txtContract_Of_Carriage.Value
        TempVars.Add "tempConsignor_Phone_Fax", Me.txtPhone_Fax.Value
        DoCmd.Close ObjectType:=acForm, ObjectName:=Me.Name, Save:=acSaveNo
    ElseIf TempVars!TempSendRecieve = "Consignee" Then
        TempVars.Add "tempConsigneeName", Me.txtCustomerName.Value
        TempVars.Add "tempConsigneeAddress", Me.txtAddress1.Value
        TempVars.Add "tempConsigneeAddress2", Me.txtAddress2.Value
        TempVars.Add "tempConsigneeZIP", Me.txtZIP.Value
        TempVars.Add "tempConsigneeCity", Me.txtCity.Value
        TempVars.Add "tempConsignee_Customer_Number", Me.txtCustomerNumber.Value
        DoCmd.Close ObjectType:=acForm, ObjectName:=Me.Name, Save:=acSaveNo
    Else
        MsgBox "Some message", vbOKOnly, "Message"
    End If
End If
End Sub

Code to enter the passed information in waybill form:
Code:
Private Sub Form_GotFocus()
If Not IsNull(TempVars!TempSendRecieve) Then
    If TempVars!TempSendRecieve = "Consignor" Then
        Me.txtConsignor_Customer_Number.Value = TempVars!tempConsignor_Customer_Number.Value
        Me.txtConsignor.Value = TempVars!tempConsignorName.Value
        Me.txtConsignor2.Value = TempVars!tempConsignorAddress
        Me.txtConsignor3.Value = TempVars!tempConsignorAddress2
        Me.txtPlace_Of_Dispatch.Value = TempVars!tempConsignorZIP & " " & TempVarsConsignorCity
        Me.txtConsignor_Pays_Code.Value = TempVars!tempConsignor_Phone_Fax
        TempVars.Remove "TempSendRecieve"
    End If
    If TempVars!TempSendRecieve = "Consignee" Then
        Me.txtConsignee_Customer_Number.Value = TempVars!tempConsignee_Customer_Number
        Me.txtConsignee.Value = TempVars!tempConsigneeName
        Me.txtConsignee2.Value = TempVars!tempConsigneeAddress
        Me.txtConsignee3.Value = TempVars!tempConsigneeAddress2
        Me.txtConsignee4.Value = TempVars!tempConsigneeZIP & " " & TempVars!tempConsigneeCity
        Me.txtPlace_Of_Discharge.Value = TempVars!tempConsigneeZIP & " " & TempVars!tempConsigneeCity
        TempVars.Remove "TempSendRecieve"
    End If
End If
End Sub

Any thoughts or ideas are welcome
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
This is what I've got so far, but I can't get it to work.
I presume you mean the part where you know which button was clicked.
For the opening of the form, I'd just pass the mode or parameter as an open argument for the opening form.

Code:
DoCmd.OpenForm "frmCustomerSelect",,acFormReadOnly,acDialog,"Consignee"

Private Sub Form_Open()
If Me.OpenArgs="Consignee" Then
Curious as to what you're doing with all those TempVars. Looks like you've already got them in a collection and are then assigning them to unbound controls for the waybill form. Did you consider a temp table instead of adding/deleting to a collection that stays in memory unless you flush it or close the db?
 
Last edited:
Upvote 0
Thanks for the reply and for making me look in another direction that I didn't think of yesterday. I've now rethinked how to do it and come up with another solution that seems to work (just a little more tweeking needed) :)
 
Upvote 0
Glad to have provided food for thought, at least.
 
Upvote 0

Forum statistics

Threads
1,221,541
Messages
6,160,418
Members
451,644
Latest member
hglymph

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top