Toggle button to fill information on another form?

galvinjaf

Registered User.
Local time
Today, 14:04
Joined
Jan 5, 2016
Messages
108
I've created two forms, and need the toggle (Yes/No)button to be able to fill in another form with two pieces of data from the form that has the toggle. (See attached example) I've manually filled in the Customer and Phone on the 'Cut' Sheet from the 'Customer Data' Form.

Is there some sort of code, that would auto fill in the information from the Customer Data form to the Cut sheet form via my 'In service' toggle button?

Thing is, The data in my customer data form will stay there for historical purposes, even if they're no longer a customer. BUT I'd need my CutSheet to either be blank (if no customer toggled in service) or have my customers info filled in on that form if toggled in service. The customer number on my Customer Data form will have multiple account numbers that are the same, so I'd need some type of error box that would say, "Customer already assigned to cut sheet, please recheck your work" or something like that should someone attempt to toggle the button to yes on the same account number of another record. Does this make sense? Any ideas?

Thanks in advance.
 

Attachments

  • Form_Toggle.jpg
    Form_Toggle.jpg
    101.3 KB · Views: 86
Sure:

Forms!SecondFormName.TextboxName = Me.TextboxName
 
Thanks for the reply! I'm getting the following error. That IS the name of my form, yet it isn't finding it?
 

Attachments

  • Error 2450.JPG
    Error 2450.JPG
    18 KB · Views: 80
  • Code Error.JPG
    Code Error.JPG
    18.6 KB · Views: 81
Is that form open? It needs to be.
 
Ahh, got it. Is there any way for the form to reference the account number associated with the cut sheet form? As it stands now, that code works, but replaces the acocunt # 1 in the first record of the second form rather than placing that text in the corresponding account number box...?
 
It looks like the accounts already exist? If so, I'd go a different way. I'd update the data directly in the table, along the lines of:

Code:
Dim strSQL As String
strSQL = "UPDATE TableName SET Customer_Name = " & Chr(34) & Me.Customer_Name & Chr(34) & " WHERE Account = " & Me.Account
CurrentDb.Execute strSQL
 
The account numbers DO exist, so this might help. When you say update the data directly in the table, what do you mean? Where do I place this code?
 
That would be behind your button, instead of copying values to another form. Basically you're updating the table directly, instead of a form based on the table.
 
This worked like a charm. I'm really impressed. Thank you very much, it is much appreciated!
 
I hate to even ask, but is it simple enough to reverse this when I untoggle the same box/button? Basically, make that account numbers 'text box' become blank if they're no longer in service?
 
Sure, either of these, depending on whether you want Null or a zero length string:

strSQL = "UPDATE TableName SET Customer_Name ='' WHERE Account = " & Me.Account

strSQL = "UPDATE TableName SET Customer_Name = Null WHERE Account = " & Me.Account
 
So place that (either) of those codes directly underneath the other code on my click event?
 
Well, if you're really using a toggle button, you'd test its value and set the appropriate string, like:

Code:
Dim strSQL As String

If Me.ToggleButton = True Then
  strSQL = "UPDATE TableName SET Customer_Name = " & Chr(34) & Me.Customer_Name & Chr(34) & " WHERE Account = " & Me.Account
Else
  strSQL = "UPDATE TableName SET Customer_Name = Null WHERE Account = " & Me.Account
End If
CurrentDb.Execute strSQL, dbFailOnError

Note I also added something to warn you if the update fails.
 

Users who are viewing this thread

Back
Top Bottom