Code Help

mrssevans

Registered User.
Local time
Today, 20:33
Joined
Nov 15, 2001
Messages
190
Here is the code that I am having problems with:
Private Sub Result_AfterUpdate()
Dim stDocName As String
Dim stLinkCriteria As String
DoCmd.Save acForm, "Customer FRM"
If [Result] = "APT" Then
DoCmd.OpenForm "AppointmentDate FRM", , , "[ResultsID]=" & Me![ResultsID]
End If
[Forms]![AppointmentDate FRM]![AppointmentDate].SetFocus
End Sub

What I am trying to do is if the feild Result (a combo box) = APT then this pop-up form will appear and allow the user to enter the date of appointment then click the back button on the form to send them back to their original form. When I use this it gives me the Access error and wants to send it to Microsoft. Can anyone help with this? Thanks in advance. sam
 
Does your combo box have two fields, ie an auto no then the description (APT)? If so try

If Me.Result.Column(1) = "APT" then

Or If Me.Result = 1 (or whatever the APT autono is) then
 
Thanks, I will give that a try. I do have two fields and that is probably the problem. Thanks again, sam
 
Private Sub Result_AfterUpdate()
If Me.txtResult = "APT" Then
DoCmd.OpenForm "AppointmentDate FRM", , , "[ResultsID]=" & Me![ResultsID]
[Forms]![AppointmentDate FRM]![AppointmentDate].SetFocus
End If
End Sub
What do you mean by a "Back" button?
Rename the control [Result] to txtResult on the property sheet. I'm not sure why you have DoCmd.Save acForm, "Customer FRM"
that's saving the form not the record.
 
Please be patient, I am a new VBer.
Here was the issue: The two forms that I am using are coming from the same table and record. I was getting an write protected error and I found a thread that said use that code to help sovle it. Indeed it did, but maybe I need to use something else from what you are saying?

The back button sends the user back to the main form after they enter their information on this pop-up form. I know that I should put it all on one form, but I am trying to protect the user from making stupid mistakes. Any ideas are welcome.
 
Instead of:
DoCmd.Save acForm, "Customer FRM"

Use:
DoCmd.RunCommand acCmdSaveRecord

I have used this with much success to prevent write conflict message boxes. Thanks to Pat Hartman for providing this solution to me.
 
Wasn't being impatient, it's just been a long hard day, I can't type very fast so trying to be brief just appears arrogant sometimes
smile.gif
I suspect it may be easier for you and users just to keep the field on the same form and just toggle its visibility based on the selection. Interested?
 
Rich I totally understand. You may have a great point, I am interested. Could you expand?
 
OK assuming your field is [AppointmentDate] add it to the form, set its visible property to no, set the name to txtAppDte.
In the On Current event put If Me.txtResult = "APT" Then
Me.txtAppDte.Visible=True
Else
Me.txtAppDte.Visible=False
End If
In the After Update event of txtResult put
Form_Current
HTH
 

Users who are viewing this thread

Back
Top Bottom