Link to home
Start Free TrialLog in
Avatar of marrossko
marrossko

asked on

How to copy the one text field into other

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
Avatar of Jonathan Kelly
Jonathan Kelly
Flag of Ireland image

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
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
Avatar of marrossko
marrossko

ASKER

Thanx for reply, but Is not working. I click on cmd button and nothing happening, even the focus is not move.
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
Hi marrossko,

Have you tried my suggestion ?
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

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

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
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
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?
ASKER CERTIFIED SOLUTION
Avatar of marrossko
marrossko

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial