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!

Problem Entering Data in Control from Unbounded Controls

Status
Not open for further replies.

jcmv007

Technical User
Nov 1, 2001
88
US
Using: MS-ACCESS 2002 SP1

I need to populate a bounded textbox (SaleDateTime) using the information the User enters in a Calendar Form and a Time Form. The values selected by the user are returned to the following unbounded textboxes: txtFrom and txtTime. I have tried using the afterupate, on change event but with no luck. How can I get it to work?

The txtFrom and txtTime are populated using forms frmReturnDateSmall and frmReturnTime. These popup when the user clicks on the command buttons called: cmdFrom and cmdTime.

All of the previous (except for the ReturnDate and ReturnTime forms) on a form called frmSale.

 
Hallo,

So are you using code to write values into txtFrom and txtTime? I guess you are as these don't trigger the AfterUpdate etc. events.

What you can do is call the AfterUpdate code specifically after writing the value into the control. Obviously you can use a completely new routine, but I'd suggest using the AfterUpdate as it's obvious what it's for and will work if the user enters txtFrom directly.

To call a forms code from another form use:
Form_frmSale.txtFrom_AfterUpdate

You'll have to make txtFrom_AfterUpdate Public so that it can be accessed outside of its own form.

That should do the trick.

- Frink

PS. I always(?) put a little comment beside any txtFrom_AfterUpdate type routines to explain why they're public and where they are called from, as it's a bit out-of-the-ordinary and will save me getting confused later...
 
Hello Frink

You are right I am using code to write values into txtFrom and txtTime. I need the user to update the txtTime last and after that have the SaleDateTime control be updated.

I implemented your suggestions and they work for the first try, but then if a change needs to be made the SaleDateTime is not updated.

Here is the code being used:
This code is in the form frmReturnTime (popup form)
Code:
Private Sub cmdOK_Click()
    Form_frmEditDetalleCodigo.txtTime_AfterUpdate
    pstrTime = Me.txtTime
    'DoCmd.Close
    DoCmd.Close acForm, "frmReturnTime", acSaveYes
End Sub

This is the main form where the SaleDateTime control is placed frmEditDetalleCodigo.
Code:
Public Sub txtTime_AfterUpdate()
Dim datDateTime As Date
strDateTime = Me.txtFrom & " " & Me.txtTime
Me.SaleDateTime = strDateTime
End Sub

Any idea what I am doing wrong?

Thanks,


James
 
Hallo,

It's a bit early on a Monday morning, but I'll give it a shot.

On initial glance, I think your problem MAY be that your Me's are getting confused. I think Me refers to the form running the code, not the form containing the code.
ie. Me.txtFrom in txtTime_AfterUpdate will refer to txtFrom on the main form, when updating the Main Form txtTime control, but will refer to the txtFrom control on the popup when called from the popup Ok button.
Not sure if that is the problem here, but you could try replacing your Me's with Forms!frmEditDetalleCodigo's in txtTime_AfterUpdate and see if that helps.

If it still doesn't work, repost and we'll have another go!

- Frink
 
Frink,

I got it to work doing the this.
In the frmReturnTime (popup form) I placed the following code
Code:
Private Sub cmdOK_Click()
    pstrTime = Forms!frmReturnTime.txtTime
    Form_frmEditDetalleCodigo.txtTimeFromNorm_AfterUpdate
    DoCmd.Close acForm, "frmReturnTime", acSaveNo
End Sub

and in the frmEditDetalleCodigo I placed this code
Code:
Public Sub txtTimeFromNorm_AfterUpdate()
    datdatetime = Me.txtDateFromNorm
    datdatetime2 = datdatetime & " " & Forms!frmReturnTime.txtTime
    'Me.FecYHoraDesdeEspNorm = Me.txtDateFromNorm & " " & Me.txtTimeFromNorm
    Forms!frmEditDetalleCodigo.FecYHoraDesdeEspNorm = datdatetime2
    Forms!frmEditDetalleCodigo.FecYHoraHastaEspNorm.SetFocus
End Sub


So now I can fill my first control but I still need to fill in another 5 more controls using the popup forms frmReturnDate and frmReturnTime. How can I code it so that the frmReturnTime triggers the corresponding control's afterupdate event for the remaining 5 controls?
 
Hallo,

I'm not sure what pstrTime in cmdOK_Click is?
And I'm not sure how your code works...
The Ok button should copy the time to the forms it needs to go to, then run the AfterUpdate event for the control just written. The AfterUpdate code must not reference frmReturnTime as it might not be open.
I would suggest:
Code:
Private Sub cmdOK_Click()
  Form_frmEditDetalleCodigo.txtTimeFromNorm = Me!txtTime
  Form_frmEditDetalleCodigo.txtTimeFromNorm_AfterUpdate
  'Repeat the above 2 lines for each target form
  DoCmd.Close acForm, "frmReturnTime", acSaveNo
End Sub
And in frmEditDetalleCodigo:
Code:
Public Sub txtTimeFromNorm_AfterUpdate()
  With Forms!frmEditDetalleCodigo
    !FecYHoraDesdeEspNorm = !txtDateFromNorm & " " & !txtTimeFromNorm
    !FecYHoraHastaEspNorm.SetFocus
  End With
End Sub
And maybe:
Code:
Public Sub txtTimeFromNorm_AfterUpdate()
  txtTimeFromNorm_AfterUpdate
End Sub
That's what I think it should be, let me know what you think,

- Frink
 
Frink,

Thank you very much for your time, here is how i got it to work.

In form frmReturnTime
Code:
Private Sub cmdOK_Click()
    Dim strCounter As String
    
    strCounter = Forms!frmEditDetalleCodigo.strUpdateCounter
    pstrTime = Forms!frmReturnTime.txtTime
      
    If strCounter = 1 Then
       Form_frmEditDetalleCodigo.txtTimeFromNorm_AfterUpdate
    ElseIf strCounter = 2 Then
        Form_frmEditDetalleCodigo.txtTimeToNorm_AfterUpdate
    ElseIf strCounter = 3 Then
        Form_frmEditDetalleCodigo.txtTimeFromEnc_AfterUpdate
    ElseIf strCounter = 4 Then
        Form_frmEditDetalleCodigo.txtTimeToEnc_AfterUpdate
    ElseIf strCounter = 5 Then
        Form_frmEditDetalleCodigo.txtTimeFromLiq_AfterUpdate
    Else
        Form_frmEditDetalleCodigo.txtTimeToLiq_AfterUpdate
    End If
    DoCmd.Close acForm, "frmReturnTime", acSaveNo
End Sub

And in the form frmEditDetalleCodigo
Code:
Private Sub cmdTimeFromNorm_Click()
    strUpdateCounter = 1
    strCallingDate = "Fecha Desde Esp. Normal " & Format(Me.txtDateFromNorm, "mmmm/dd/yyyy")
    Forms!frmEditDetalleCodigo.txtTimeFromNorm = ReturnTime(Nz(Me.txtTimeFromNorm, ""))
End Sub

The way I solve the update problem was using "Forms!frmReturnTime.txtTime"

Code:
Public Sub txtTimeFromEnc_AfterUpdate()
    strUpdateCounter = ""
    strCallingDate = ""
    Me.FecYHoraDesdeEspEnca = Me.txtDateFromEnc & " " & Forms!frmReturnTime.txtTime
    Me.FecYHoraHastaEspEnca.SetFocus
End Sub

Thanks again for your time it was of great help in finding my solution.

James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top