Problems with code

G

Greg

On my main form I have a combo box where I am pulling respected phone number
based on group issue is assigned to. Here is the code:

Private Sub lstGroup_AfterUpdate()
Dim HasPhone As Variant

HasPhone = Me.lstGroup.Column(1)
If Len(HasPhone & "") = 0 Then
Me.txtPhoneday.Visible = False
Me.txtPhoneNight.Visible = False
Me.txtPhoneday = ""
Me.txtPhoneNight = ""
Else
Me.txtPhoneday.Visible = True
Me.txtPhoneNight.Visible = True
Me.txtPhoneday = HasPhone
Me.txtPhoneNight = Me.lstGroup.Column(2)
End If
End Sub

On the same form I have a subform where is am displaying issues that are
still outstanding. I want to click on record on a subform and display
ticket#, group and phone number. It is somehow working; however I noticed
that phone number is not being display correctly. Most of the time is a
number from previous record on a subform. Here is the code I am using on the
subform:


Private Sub Form_DblClick(Cancel As Integer)
Dim lngTicket As Long
Dim HasPhone As Variant

lngTicket = Me.[Ticket #]
HasPhone = Me.Parent.[lstGroup].Column(1)

If Len(HasPhone & "") = 0 Then
Me.Parent.[txtPhoneday].Visible = False
Me.Parent.[txtPhoneNight].Visible = False
Me.Parent.[txtPhoneday] = ""
Me.Parent.[txtPhoneNight] = ""
Else
Me.Parent.[txtPhoneday].Visible = True
Me.Parent.[txtPhoneNight].Visible = True
Me.Parent.[txtPhoneday] = HasPhone
Me.Parent.[txtPhoneNight] = Me.Parent.[lstGroup].Column(2)

End If

Me.Parent.Requery
Me.Parent.Recordset.FindFirst "[Ticket #]=" & lngTicket
Forms![Remedy Tickets]![Status].SetFocus
End Sub

Thanks for your help
 
S

Stefan Hoffmann

hi Greg,
Private Sub lstGroup_AfterUpdate()
Dim HasPhone As Variant

HasPhone = Me.lstGroup.Column(1)
If Len(HasPhone & "") = 0 Then
Me.txtPhoneday.Visible = False
Me.txtPhoneNight.Visible = False
Me.txtPhoneday = ""
Me.txtPhoneNight = ""
Else
Me.txtPhoneday.Visible = True
Me.txtPhoneNight.Visible = True
Me.txtPhoneday = HasPhone
Me.txtPhoneNight = Me.lstGroup.Column(2)
End If
End Sub
A variable called HasSomething should be a boolean, not a variant, e.g:

Private Sub lstGroup_AfterUpdate()

Dim HasPhone As Boolean

HasPhone = (Len(lstGroup.Column(1) & "") > 0)

txtPhoneday.Value = lstGroup.Column(1)
txtPhoneday.Visible = HasPhone

If HasPhone Then
txtPhoneNight.Value = lstGroup.Column(2)
Else
txtPhoneNight.Value = ""
End If
txtPhoneNight.Visible = HasPhone

End Sub
Private Sub Form_DblClick(Cancel As Integer)
Dim lngTicket As Long
lngTicket = Me.[Ticket #]

Me.Parent.Requery
Me.Parent.Recordset.FindFirst "[Ticket #]=" & lngTicket
Forms![Remedy Tickets]![Status].SetFocus
End Sub
The problem is that you requery your parent form, this leads to reload
of your sub form. Depending on the sub form control, bound or not, and
the kind of data, single record set or more, you cannot assume that it
will display the same record set as before the Me.Parent.Requery.

btw, you should rename your fields:

http://www.mvps.org/access/tencommandments.htm

mfG
--> stefan <--
 
R

Rudolf Lamour

Greg said:
On my main form I have a combo box where I am pulling respected phone
number
based on group issue is assigned to. Here is the code:

Private Sub lstGroup_AfterUpdate()
Dim HasPhone As Variant

HasPhone = Me.lstGroup.Column(1)
If Len(HasPhone & "") = 0 Then
Me.txtPhoneday.Visible = False
Me.txtPhoneNight.Visible = False
Me.txtPhoneday = ""
Me.txtPhoneNight = ""
Else
Me.txtPhoneday.Visible = True
Me.txtPhoneNight.Visible = True
Me.txtPhoneday = HasPhone
Me.txtPhoneNight = Me.lstGroup.Column(2)
End If
End Sub

On the same form I have a subform where is am displaying issues that are
still outstanding. I want to click on record on a subform and display
ticket#, group and phone number. It is somehow working; however I noticed
that phone number is not being display correctly. Most of the time is a
number from previous record on a subform. Here is the code I am using on
the
subform:


Private Sub Form_DblClick(Cancel As Integer)
Dim lngTicket As Long
Dim HasPhone As Variant

lngTicket = Me.[Ticket #]
HasPhone = Me.Parent.[lstGroup].Column(1)

If Len(HasPhone & "") = 0 Then
Me.Parent.[txtPhoneday].Visible = False
Me.Parent.[txtPhoneNight].Visible = False
Me.Parent.[txtPhoneday] = ""
Me.Parent.[txtPhoneNight] = ""
Else
Me.Parent.[txtPhoneday].Visible = True
Me.Parent.[txtPhoneNight].Visible = True
Me.Parent.[txtPhoneday] = HasPhone
Me.Parent.[txtPhoneNight] = Me.Parent.[lstGroup].Column(2)

End If

Me.Parent.Requery
Me.Parent.Recordset.FindFirst "[Ticket #]=" & lngTicket
Forms![Remedy Tickets]![Status].SetFocus
End Sub

Thanks for your help
 
R

Rudolf Lamour

Greg said:
On my main form I have a combo box where I am pulling respected phone
number
based on group issue is assigned to. Here is the code:

Private Sub lstGroup_AfterUpdate()
Dim HasPhone As Variant

HasPhone = Me.lstGroup.Column(1)
If Len(HasPhone & "") = 0 Then
Me.txtPhoneday.Visible = False
Me.txtPhoneNight.Visible = False
Me.txtPhoneday = ""
Me.txtPhoneNight = ""
Else
Me.txtPhoneday.Visible = True
Me.txtPhoneNight.Visible = True
Me.txtPhoneday = HasPhone
Me.txtPhoneNight = Me.lstGroup.Column(2)
End If
End Sub

On the same form I have a subform where is am displaying issues that are
still outstanding. I want to click on record on a subform and display
ticket#, group and phone number. It is somehow working; however I noticed
that phone number is not being display correctly. Most of the time is a
number from previous record on a subform. Here is the code I am using on
the
subform:


Private Sub Form_DblClick(Cancel As Integer)
Dim lngTicket As Long
Dim HasPhone As Variant

lngTicket = Me.[Ticket #]
HasPhone = Me.Parent.[lstGroup].Column(1)

If Len(HasPhone & "") = 0 Then
Me.Parent.[txtPhoneday].Visible = False
Me.Parent.[txtPhoneNight].Visible = False
Me.Parent.[txtPhoneday] = ""
Me.Parent.[txtPhoneNight] = ""
Else
Me.Parent.[txtPhoneday].Visible = True
Me.Parent.[txtPhoneNight].Visible = True
Me.Parent.[txtPhoneday] = HasPhone
Me.Parent.[txtPhoneNight] = Me.Parent.[lstGroup].Column(2)

End If

Me.Parent.Requery
Me.Parent.Recordset.FindFirst "[Ticket #]=" & lngTicket
Forms![Remedy Tickets]![Status].SetFocus
End Sub

Thanks for your help
 
R

Rudolf Lamour

Greg said:
On my main form I have a combo box where I am pulling respected phone
number
based on group issue is assigned to. Here is the code:

Private Sub lstGroup_AfterUpdate()
Dim HasPhone As Variant

HasPhone = Me.lstGroup.Column(1)
If Len(HasPhone & "") = 0 Then
Me.txtPhoneday.Visible = False
Me.txtPhoneNight.Visible = False
Me.txtPhoneday = ""
Me.txtPhoneNight = ""
Else
Me.txtPhoneday.Visible = True
Me.txtPhoneNight.Visible = True
Me.txtPhoneday = HasPhone
Me.txtPhoneNight = Me.lstGroup.Column(2)
End If
End Sub

On the same form I have a subform where is am displaying issues that are
still outstanding. I want to click on record on a subform and display
ticket#, group and phone number. It is somehow working; however I noticed
that phone number is not being display correctly. Most of the time is a
number from previous record on a subform. Here is the code I am using on
the
subform:


Private Sub Form_DblClick(Cancel As Integer)
Dim lngTicket As Long
Dim HasPhone As Variant

lngTicket = Me.[Ticket #]
HasPhone = Me.Parent.[lstGroup].Column(1)

If Len(HasPhone & "") = 0 Then
Me.Parent.[txtPhoneday].Visible = False
Me.Parent.[txtPhoneNight].Visible = False
Me.Parent.[txtPhoneday] = ""
Me.Parent.[txtPhoneNight] = ""
Else
Me.Parent.[txtPhoneday].Visible = True
Me.Parent.[txtPhoneNight].Visible = True
Me.Parent.[txtPhoneday] = HasPhone
Me.Parent.[txtPhoneNight] = Me.Parent.[lstGroup].Column(2)

End If

Me.Parent.Requery
Me.Parent.Recordset.FindFirst "[Ticket #]=" & lngTicket
Forms![Remedy Tickets]![Status].SetFocus
End Sub

Thanks for your help
 
R

Rudolf Lamour

Greg said:
On my main form I have a combo box where I am pulling respected phone
number
based on group issue is assigned to. Here is the code:

Private Sub lstGroup_AfterUpdate()
Dim HasPhone As Variant

HasPhone = Me.lstGroup.Column(1)
If Len(HasPhone & "") = 0 Then
Me.txtPhoneday.Visible = False
Me.txtPhoneNight.Visible = False
Me.txtPhoneday = ""
Me.txtPhoneNight = ""
Else
Me.txtPhoneday.Visible = True
Me.txtPhoneNight.Visible = True
Me.txtPhoneday = HasPhone
Me.txtPhoneNight = Me.lstGroup.Column(2)
End If
End Sub

On the same form I have a subform where is am displaying issues that are
still outstanding. I want to click on record on a subform and display
ticket#, group and phone number. It is somehow working; however I noticed
that phone number is not being display correctly. Most of the time is a
number from previous record on a subform. Here is the code I am using on
the
subform:


Private Sub Form_DblClick(Cancel As Integer)
Dim lngTicket As Long
Dim HasPhone As Variant

lngTicket = Me.[Ticket #]
HasPhone = Me.Parent.[lstGroup].Column(1)

If Len(HasPhone & "") = 0 Then
Me.Parent.[txtPhoneday].Visible = False
Me.Parent.[txtPhoneNight].Visible = False
Me.Parent.[txtPhoneday] = ""
Me.Parent.[txtPhoneNight] = ""
Else
Me.Parent.[txtPhoneday].Visible = True
Me.Parent.[txtPhoneNight].Visible = True
Me.Parent.[txtPhoneday] = HasPhone
Me.Parent.[txtPhoneNight] = Me.Parent.[lstGroup].Column(2)

End If

Me.Parent.Requery
Me.Parent.Recordset.FindFirst "[Ticket #]=" & lngTicket
Forms![Remedy Tickets]![Status].SetFocus
End Sub

Thanks for your help
 
R

Rudolf Lamour

Greg said:
On my main form I have a combo box where I am pulling respected phone
number
based on group issue is assigned to. Here is the code:

Private Sub lstGroup_AfterUpdate()
Dim HasPhone As Variant

HasPhone = Me.lstGroup.Column(1)
If Len(HasPhone & "") = 0 Then
Me.txtPhoneday.Visible = False
Me.txtPhoneNight.Visible = False
Me.txtPhoneday = ""
Me.txtPhoneNight = ""
Else
Me.txtPhoneday.Visible = True
Me.txtPhoneNight.Visible = True
Me.txtPhoneday = HasPhone
Me.txtPhoneNight = Me.lstGroup.Column(2)
End If
End Sub

On the same form I have a subform where is am displaying issues that are
still outstanding. I want to click on record on a subform and display
ticket#, group and phone number. It is somehow working; however I noticed
that phone number is not being display correctly. Most of the time is a
number from previous record on a subform. Here is the code I am using on
the
subform:


Private Sub Form_DblClick(Cancel As Integer)
Dim lngTicket As Long
Dim HasPhone As Variant

lngTicket = Me.[Ticket #]
HasPhone = Me.Parent.[lstGroup].Column(1)

If Len(HasPhone & "") = 0 Then
Me.Parent.[txtPhoneday].Visible = False
Me.Parent.[txtPhoneNight].Visible = False
Me.Parent.[txtPhoneday] = ""
Me.Parent.[txtPhoneNight] = ""
Else
Me.Parent.[txtPhoneday].Visible = True
Me.Parent.[txtPhoneNight].Visible = True
Me.Parent.[txtPhoneday] = HasPhone
Me.Parent.[txtPhoneNight] = Me.Parent.[lstGroup].Column(2)

End If

Me.Parent.Requery
Me.Parent.Recordset.FindFirst "[Ticket #]=" & lngTicket
Forms![Remedy Tickets]![Status].SetFocus
End Sub

Thanks for your help
 
R

Rudolf Lamour

Greg said:
On my main form I have a combo box where I am pulling respected phone
number
based on group issue is assigned to. Here is the code:

Private Sub lstGroup_AfterUpdate()
Dim HasPhone As Variant

HasPhone = Me.lstGroup.Column(1)
If Len(HasPhone & "") = 0 Then
Me.txtPhoneday.Visible = False
Me.txtPhoneNight.Visible = False
Me.txtPhoneday = ""
Me.txtPhoneNight = ""
Else
Me.txtPhoneday.Visible = True
Me.txtPhoneNight.Visible = True
Me.txtPhoneday = HasPhone
Me.txtPhoneNight = Me.lstGroup.Column(2)
End If
End Sub

On the same form I have a subform where is am displaying issues that are
still outstanding. I want to click on record on a subform and display
ticket#, group and phone number. It is somehow working; however I noticed
that phone number is not being display correctly. Most of the time is a
number from previous record on a subform. Here is the code I am using on
the
subform:


Private Sub Form_DblClick(Cancel As Integer)
Dim lngTicket As Long
Dim HasPhone As Variant

lngTicket = Me.[Ticket #]
HasPhone = Me.Parent.[lstGroup].Column(1)

If Len(HasPhone & "") = 0 Then
Me.Parent.[txtPhoneday].Visible = False
Me.Parent.[txtPhoneNight].Visible = False
Me.Parent.[txtPhoneday] = ""
Me.Parent.[txtPhoneNight] = ""
Else
Me.Parent.[txtPhoneday].Visible = True
Me.Parent.[txtPhoneNight].Visible = True
Me.Parent.[txtPhoneday] = HasPhone
Me.Parent.[txtPhoneNight] = Me.Parent.[lstGroup].Column(2)

End If

Me.Parent.Requery
Me.Parent.Recordset.FindFirst "[Ticket #]=" & lngTicket
Forms![Remedy Tickets]![Status].SetFocus
End Sub

Thanks for your help
 
R

Rudolf Lamour

Greg said:
On my main form I have a combo box where I am pulling respected phone
number
based on group issue is assigned to. Here is the code:

Private Sub lstGroup_AfterUpdate()
Dim HasPhone As Variant

HasPhone = Me.lstGroup.Column(1)
If Len(HasPhone & "") = 0 Then
Me.txtPhoneday.Visible = False
Me.txtPhoneNight.Visible = False
Me.txtPhoneday = ""
Me.txtPhoneNight = ""
Else
Me.txtPhoneday.Visible = True
Me.txtPhoneNight.Visible = True
Me.txtPhoneday = HasPhone
Me.txtPhoneNight = Me.lstGroup.Column(2)
End If
End Sub

On the same form I have a subform where is am displaying issues that are
still outstanding. I want to click on record on a subform and display
ticket#, group and phone number. It is somehow working; however I noticed
that phone number is not being display correctly. Most of the time is a
number from previous record on a subform. Here is the code I am using on
the
subform:


Private Sub Form_DblClick(Cancel As Integer)
Dim lngTicket As Long
Dim HasPhone As Variant

lngTicket = Me.[Ticket #]
HasPhone = Me.Parent.[lstGroup].Column(1)

If Len(HasPhone & "") = 0 Then
Me.Parent.[txtPhoneday].Visible = False
Me.Parent.[txtPhoneNight].Visible = False
Me.Parent.[txtPhoneday] = ""
Me.Parent.[txtPhoneNight] = ""
Else
Me.Parent.[txtPhoneday].Visible = True
Me.Parent.[txtPhoneNight].Visible = True
Me.Parent.[txtPhoneday] = HasPhone
Me.Parent.[txtPhoneNight] = Me.Parent.[lstGroup].Column(2)

End If

Me.Parent.Requery
Me.Parent.Recordset.FindFirst "[Ticket #]=" & lngTicket
Forms![Remedy Tickets]![Status].SetFocus
End Sub

Thanks for your help
 
R

Rudolf Lamour

Greg said:
On my main form I have a combo box where I am pulling respected phone
number
based on group issue is assigned to. Here is the code:

Private Sub lstGroup_AfterUpdate()
Dim HasPhone As Variant

HasPhone = Me.lstGroup.Column(1)
If Len(HasPhone & "") = 0 Then
Me.txtPhoneday.Visible = False
Me.txtPhoneNight.Visible = False
Me.txtPhoneday = ""
Me.txtPhoneNight = ""
Else
Me.txtPhoneday.Visible = True
Me.txtPhoneNight.Visible = True
Me.txtPhoneday = HasPhone
Me.txtPhoneNight = Me.lstGroup.Column(2)
End If
End Sub

On the same form I have a subform where is am displaying issues that are
still outstanding. I want to click on record on a subform and display
ticket#, group and phone number. It is somehow working; however I noticed
that phone number is not being display correctly. Most of the time is a
number from previous record on a subform. Here is the code I am using on
the
subform:


Private Sub Form_DblClick(Cancel As Integer)
Dim lngTicket As Long
Dim HasPhone As Variant

lngTicket = Me.[Ticket #]
HasPhone = Me.Parent.[lstGroup].Column(1)

If Len(HasPhone & "") = 0 Then
Me.Parent.[txtPhoneday].Visible = False
Me.Parent.[txtPhoneNight].Visible = False
Me.Parent.[txtPhoneday] = ""
Me.Parent.[txtPhoneNight] = ""
Else
Me.Parent.[txtPhoneday].Visible = True
Me.Parent.[txtPhoneNight].Visible = True
Me.Parent.[txtPhoneday] = HasPhone
Me.Parent.[txtPhoneNight] = Me.Parent.[lstGroup].Column(2)

End If

Me.Parent.Requery
Me.Parent.Recordset.FindFirst "[Ticket #]=" & lngTicket
Forms![Remedy Tickets]![Status].SetFocus
End Sub

Thanks for your help
 
R

Rudolf Lamour

Rudolf Lamour said:
Greg said:
On my main form I have a combo box where I am pulling respected phone
number
based on group issue is assigned to. Here is the code:

Private Sub lstGroup_AfterUpdate()
Dim HasPhone As Variant

HasPhone = Me.lstGroup.Column(1)
If Len(HasPhone & "") = 0 Then
Me.txtPhoneday.Visible = False
Me.txtPhoneNight.Visible = False
Me.txtPhoneday = ""
Me.txtPhoneNight = ""
Else
Me.txtPhoneday.Visible = True
Me.txtPhoneNight.Visible = True
Me.txtPhoneday = HasPhone
Me.txtPhoneNight = Me.lstGroup.Column(2)
End If
End Sub

On the same form I have a subform where is am displaying issues that are
still outstanding. I want to click on record on a subform and display
ticket#, group and phone number. It is somehow working; however I
noticed
that phone number is not being display correctly. Most of the time is a
number from previous record on a subform. Here is the code I am using on
the
subform:


Private Sub Form_DblClick(Cancel As Integer)
Dim lngTicket As Long
Dim HasPhone As Variant

lngTicket = Me.[Ticket #]
HasPhone = Me.Parent.[lstGroup].Column(1)

If Len(HasPhone & "") = 0 Then
Me.Parent.[txtPhoneday].Visible = False
Me.Parent.[txtPhoneNight].Visible = False
Me.Parent.[txtPhoneday] = ""
Me.Parent.[txtPhoneNight] = ""
Else
Me.Parent.[txtPhoneday].Visible = True
Me.Parent.[txtPhoneNight].Visible = True
Me.Parent.[txtPhoneday] = HasPhone
Me.Parent.[txtPhoneNight] = Me.Parent.[lstGroup].Column(2)

End If

Me.Parent.Requery
Me.Parent.Recordset.FindFirst "[Ticket #]=" & lngTicket
Forms![Remedy Tickets]![Status].SetFocus
End Sub

Thanks for your help
 
R

Rudolf Lamour

Rudolf Lamour said:
Greg said:
On my main form I have a combo box where I am pulling respected phone
number
based on group issue is assigned to. Here is the code:

Private Sub lstGroup_AfterUpdate()
Dim HasPhone As Variant

HasPhone = Me.lstGroup.Column(1)
If Len(HasPhone & "") = 0 Then
Me.txtPhoneday.Visible = False
Me.txtPhoneNight.Visible = False
Me.txtPhoneday = ""
Me.txtPhoneNight = ""
Else
Me.txtPhoneday.Visible = True
Me.txtPhoneNight.Visible = True
Me.txtPhoneday = HasPhone
Me.txtPhoneNight = Me.lstGroup.Column(2)
End If
End Sub

On the same form I have a subform where is am displaying issues that are
still outstanding. I want to click on record on a subform and display
ticket#, group and phone number. It is somehow working; however I
noticed
that phone number is not being display correctly. Most of the time is a
number from previous record on a subform. Here is the code I am using on
the
subform:


Private Sub Form_DblClick(Cancel As Integer)
Dim lngTicket As Long
Dim HasPhone As Variant

lngTicket = Me.[Ticket #]
HasPhone = Me.Parent.[lstGroup].Column(1)

If Len(HasPhone & "") = 0 Then
Me.Parent.[txtPhoneday].Visible = False
Me.Parent.[txtPhoneNight].Visible = False
Me.Parent.[txtPhoneday] = ""
Me.Parent.[txtPhoneNight] = ""
Else
Me.Parent.[txtPhoneday].Visible = True
Me.Parent.[txtPhoneNight].Visible = True
Me.Parent.[txtPhoneday] = HasPhone
Me.Parent.[txtPhoneNight] = Me.Parent.[lstGroup].Column(2)

End If

Me.Parent.Requery
Me.Parent.Recordset.FindFirst "[Ticket #]=" & lngTicket
Forms![Remedy Tickets]![Status].SetFocus
End Sub

Thanks for your help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top