Inserting current from open form to another form. (1 Viewer)

Fira_g

Registered User.
Local time
Yesterday, 23:56
Joined
Oct 17, 2019
Messages
60
I have a customer form where I need a button that should copy/insert the CustomerID value to CustomerID field on the main form.

The CustomerID on the main form is a combobox with a query that selects values from the customer table.

I tried this code and it opens the main form with CustomerID field empty. I guess it is because of the CustomerID on the main form being a combobox.

Code:
Private Sub InserttoMainOrder_Click()
If IsNull(Me.CustomerID) Then
    MsgBox "Please Select a Company First", vbOKOnly
    Me.CustomerID.SetFocus
    Exit Sub
End If

DoCmd.OpenForm "frmMainOrders", , , "CustomerID = " & Me.CustomerID
End Sub

Could you please advise how to solve this?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 20:56
Joined
Oct 29, 2018
Messages
21,455
Hi. Just curious, have you considered using a form/subform setup, so you don't have to worry about "copying" data from one form to another?
 

Fira_g

Registered User.
Local time
Yesterday, 23:56
Joined
Oct 17, 2019
Messages
60
What I meant is that, I have a customer form and let say I just entered new customer details or selected existing one and want to create new order for him. As I am on this form, instead of closing this form and going to the main form to create new order for him, I just click a button on the customer form which will open the main form with the customer name already inserted in the appropriate field.

Hope that is not confusing :)
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 20:56
Joined
Oct 29, 2018
Messages
21,455
What I meant is that, I have a customer form and let say I just entered new customer details or selected existing one and want to create new order for him. As I am on this form, instead of closing this form and going to the main form to create new order for him, I just click a button on the customer form which will open the main form with the customer name already inserted in the appropriate field.

Hope that is not confusing :)
Hi. No, that is not confusing. I was just trying to say there may be a simpler approach than what you are currently using or thinking of using. For example, if you're on the Customer form, how exactly do you add new customers? It sounds like you have to open another form just to add a new customer when I think you should be able to simply add the new customer on the same form you were already on.
 

Fira_g

Registered User.
Local time
Yesterday, 23:56
Joined
Oct 17, 2019
Messages
60
I have an Order table with FK CustomerID from Cusotmers table and some other fields. I've created a form based on the Order table.
On the Order Form i just need the CustomerID (which is a combobox with select query), that is all the info I need about the customer on that form.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 20:56
Joined
Oct 29, 2018
Messages
21,455
I have an Order table with FK CustomerID from Cusotmers table and some other fields. I've created a form based on the Order table.
On the Order Form i just need the CustomerID (which is a combobox with select query), that is all the info I need about the customer on that form.
Hi. Are you familiar with a form/subform setup? I was just saying if you could embed your order form as a subform to your customer form, then assigning the customer id to each order will be done for you, automatically, by Access.
 

jdraw

Super Moderator
Staff member
Local time
Yesterday, 23:56
Joined
Jan 23, 2006
Messages
15,379
Can you show us a graphic of your tables and relationships (relationships window)?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 20:56
Joined
Oct 29, 2018
Messages
21,455
I would be interested in seeing the forms...
 

Fira_g

Registered User.
Local time
Yesterday, 23:56
Joined
Oct 17, 2019
Messages
60
Here you go :
 

Attachments

  • main.png
    main.png
    26 KB · Views: 107
  • relat.png
    relat.png
    92.6 KB · Views: 93

Fira_g

Registered User.
Local time
Yesterday, 23:56
Joined
Oct 17, 2019
Messages
60
I am, I have a subform on my main form and few others.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 20:56
Joined
Oct 29, 2018
Messages
21,455
I am, I have a subform on my main form and few others.
Okay, so back to my original question then. Have you considered using it for your orders form, so you don't have to worry about copying the customer ID back and forth? Just wondering...
 

Fira_g

Registered User.
Local time
Yesterday, 23:56
Joined
Oct 17, 2019
Messages
60
Okay, so back to my original question then. Have you considered using it for your orders form, so you don't have to worry about copying the customer ID back and forth? Just wondering...

I am not sure if you checked the screenshot of the Order form I attached.
Are you suggesting adding customer subform to the order form?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 20:56
Joined
Oct 29, 2018
Messages
21,455
I am not sure if you checked the screenshot of the Order form I attached.
Are you suggesting adding customer subform to the order form?
No, the opposite. Add your order form as a subform to the customer form (just like in the sample in the link I posted earlier).


PS. Unless, of course, each order belongs to multiple customers. If so, then yes, I am suggesting what you said. However, my original impression is each customer will have multiple orders; hence, the suggestion I described above.
 

Fira_g

Registered User.
Local time
Yesterday, 23:56
Joined
Oct 17, 2019
Messages
60
What if I need to add just a new customer without creating an order for him?
 

Fira_g

Registered User.
Local time
Yesterday, 23:56
Joined
Oct 17, 2019
Messages
60
And the subject of this thread should read:
"Inserting currentRecord from open form to another form.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 20:56
Joined
Oct 29, 2018
Messages
21,455
Any suggestion regarding the relationships? :rolleyes:
Hi. If you don't mind, I do have a couple of questions about it.

  1. What is the difference between Pick and Drop locations?
  2. In tblOrders, does EmployeeID refers to the person who took the order?
  3. Are drivers not considered as "employees?" If they are, how come they're not in the Employees table?
That's it for now...
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 20:56
Joined
Oct 29, 2018
Messages
21,455
And the subject of this thread should read:
"Inserting currentRecord from open form to another form.
Hi. That's not really the same as what I thought you were asking. I thought you were wanting to know how to transfer/copy the CustomerID value from one form to another. A CustomerID value is just one value, it is not really a "record."


In any case, if you are looking for a way to copy the current CustomerID on your form to another, you could try the following syntax:


Forms!NameOfOtherForm.NameOfControlOnThatForm = Me.CustomerID


However, for the above syntax to work, the other form must also be open to accept the value you are transferring.


If you are truly asking how to copy an entire record from one form into another, that would involve a different approach/syntax.
 

Fira_g

Registered User.
Local time
Yesterday, 23:56
Joined
Oct 17, 2019
Messages
60
Hi. That's not really the same as what I thought you were asking. I thought you were wanting to know how to transfer/copy the CustomerID value from one form to another. A CustomerID value is just one value, it is not really a "record."

That is exactly what I want, value of one field to transfer to another, I need to get the terms right. )
 

Users who are viewing this thread

Top Bottom