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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transfering data from record to record via command button 1

Status
Not open for further replies.

WallT

Vendor
Aug 13, 2002
247
US
I am having a tough time with my limited knowledge of VB on transferring data to the next record. Here goes...

I have a subform that is set to "Single Form". I have a command button on that subform that is a basic DoCmd.GoToRecord , , acNewRec.

The subform is Locations for an Order. The subform will always have multiple locations, however, a lot of the times some of the data is the same in certain fields. I just want to transfer the data from fields 1 and 2 in location number 1, to fields 1 and 2 in location number 2.

I hope this makes sense. I figured out how to do it from one form to another, but not from one record to another...help...
 
In the Click event procedure of your button, before the GoToRecord call, set the DefaultValue property of the controls to their actual value.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
ARe you saying to use the "Transfer Text" command?
 
No. Something like this:
Me![textbox1].DefaultValue = Me![textbox1].Value

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I tried the following and I am getting the old #Name? error

Me![cmbServiceAddress].DefaultValue = Me[cmbServiceAddress].Value
DoCmd.GoToRecord , , acNewRec
Me.cboServerID.SetFocus
 
Use the expression builder to avoid spelling issue.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Still getting the error appearing in the text box... #Name?

Here the whole thing in case I am missing something somewhere else...spelling is good.

Private Sub cmd_NewEntitySameLoc_Click()
On Error GoTo Err_cmd_NewEntitySameLoc_Click
Me.[cmbServiceAddress].DefaultValue = Me.[cmbServiceAddress].Value
DoCmd.GoToRecord , , acNewRec
Me.cboServerID.SetFocus
Exit_cmd_NewEntitySameLoc_Click:
Exit Sub
Err_cmd_NewEntitySameLoc_Click:
If Err.Number = 2105 Then
Exit Sub
Else
MsgBox Err.Description
Resume Exit_cmd_NewEntitySameLoc_Click
End If
End Sub
 
You may try this:
Code:
"'" & Me.[cmbServiceAddress].DefaultValue = Me.[cmbServiceAddress].Value & "'"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I get a compile error on that one
 
Sorry for the typo :~/
Code:
Me.[cmbServiceAddress].DefaultValue = "'" & Me.[cmbServiceAddress].Value & "'"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Bam!...awesome...thank you.

I am assuming that is for a text value...what if the text box was a numeric value?
 
Don't use quotes at all.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Ok, I am having to revisit here. I am having trouble with Nulls on this. If one of the fields I am transffering data from has no text, then the record wont save. I get the following error:

Field 'tblEntities.ServiceCity' cannot be a zero-length string.

tblEntities is obviously the table, but the ServiceCity is the field in the table. The text box on the form is txt_ServiceCity.

How can I handle the nulls on this? Am I going to have to do something like If Not(Is Null(Me.blah blah))Then transfer?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top