We help IT Professionals succeed at work.

How to copy the one text field into other

marrossko
marrossko asked
on
Hi experts,
i need help with my solution. I have a main form "frmFaults" and subform "sfrLogBook" In the main form I have text fields txtDate, txtName and txtPhoneNumber. In the subform I have fields txtLogName, txtLogDate and txtLogPNumber. On main form I have the command button cmdAdd.
Now what i need to do is when the cmdAdd is hit, content of the fields in main form frmFaults is copy as a new record into subform (txtDate -> txtLogDate, txtName -> txtLogName, txtPhoneNumber -> txtLogPNumber). So this way I can create the list of the log about faults. The option could be erasing the fields in the main form.

Tahnx
Comment
Watch Question

CERTIFIED EXPERT

Commented:
Hi marrossko,

I would use an Append Query to achieve this.

INSERT INTO LogBook_Table ( tDate, tLogDate, tName, tLogName, tPhone, tLogPNum )
SELECT
[Forms]![frmFaults]![txtDate] AS Expr1,
[Forms]![frmFaults]![txtLogDate] AS Expr2,
[Forms]![frmFaults]![txtName] AS Expr3,
 [Forms]![frmFaults]![txtLogName] AS Expr4,
[Forms]![frmFaults]![txtPhone] AS Expr5,
[Forms]![frmFaults]![txttLogNum] AS Expr6;

Save the query as something like "AppendLogRecord"
On the On Click Event of your add button
call the query
Docmd.OpenQuery "AppendLogRecord"

You can use
Docmd.SetWarnings False to turn off the prompt.

Docmd.SetWarnings False
Docmd.OpenQuery "AppendLogRecord"
Docmd.SetWarnings True

You should probably check that each field has a valid value before you call the query.

Rgds,
Datrias

Commented:
Dim TDate, TName, TPhoneNumber

TDate = Me!TXTDate
TName = Me!TXTDate
TPhoneNumber = Me!TXTPhoneNumber

Forms!frmFaults.sfrLogBook.Form.setfocus
DoCmd.GoToRecord , , acNewRec

Me.txtLogName = TName
Me.field2 = TDate 'Change field Name
Me.Field3 = TPhoneNumber 'Change Field Name

Author

Commented:
Thanx for reply, but Is not working. I click on cmd button and nothing happening, even the focus is not move.

Author

Commented:
I struggle with this...I'm trying to break-down the code step by step and I realized that I cant even move the focus from the main form to control in the subform. When i click on the cmdAdd it should move the focus into the txtText1 text field. I have this code under the cmd:

[Forms]![frmFaults]![sfrLogBook].[Form]![txtText1].SetFocus

Is there something wrong with this statement what I can not see? Please advise.
Tahnx
marrossko
CERTIFIED EXPERT

Commented:
Hi marrossko,

Have you tried my suggestion ?

Author

Commented:
Hi Datrias,
I have a problem to apply your solution. Thing is the form frmFaults using the table tblFaults and subform sfrLogBook using table tblLogFaults. But this text fields txtDate, txtName and txtPhoneNumber in the frmFaults are unbanut. Even though they are not link with table tblFaults, the content of it has to be copy/move to the proper text fields in the subform. So the query is not really a solution for my case. So I thought that something like this would help, but not:

Me.txtName = [Forms]![frmFaults]![sfrLogBook].[Form]![txtLogName]

Even if I try to move the focus on the text field txtLogName is not working. It could be some syntax error or some misspelling but I can not see it.
Eny other suggestions?

marrossko

Commented:
Forms!frmFaults.sfrLogBook.Form.Setfocus
Forms!frmFaults.sfrLogBook.Form.txtLogName.Setfocus

CERTIFIED EXPERT

Commented:
Hi  marrossko:

Apologies for long delay.

The text fields do not have to be bound to form frmFaults for my solution to work.

Rgds,
Datrias

Author

Commented:
Hi Datrias,
I tryed to create the query but I mesed-up my db. I had to go back to my back-up. I think there has to be a solution with tables. So far I can't figured-out why the hell it doesn't want to move the focus from main form into text field in subform.

marrossko

Author

Commented:
Why am I ask to provide my login and password for some upload??? I'm using this page for two yeras an I heve been never ask to do it!! Can you explain?
So finally I figured out...This is the code, which is doing exactly what i was need it! Even I'm not very happy with it (doesn't look "pro"):
Private Sub Command168_Click()

    DoCmd.GoToControl "sfrLogBook"
    DoCmd.GoToControl "txtLogDate"
    DoCmd.GoToRecord , , acNewRec
    Forms!frmFaults!sfrLogBook.Form.txtLogDate = Forms!frmFaults.txtCaseDate
   etc.

But thanks
CERTIFIED EXPERT

Commented:
cool

Explore More ContentExplore courses, solutions, and other research materials related to this topic.