combine codes

G

Guest

Code (1) Created by wizard to refresh the “Location†combobox
Private Sub Location_AfterUpdate()
On Error GoTo Err_Refresh__Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

Exit_Refresh__Click:
Exit Sub

Err_Refresh__Click:
MsgBox Err.Description
Resume Exit_Refresh__Click
End If
End Sub

Code (2)
Private Sub Location_AfterUpdate()
If Not IsNull(Me![Location]) Then
Me![CargoTallyID] = [Forms]![CargoTallyfrm].[CargoTallyID]
ElseIf IsNull(Me![Location]) Then
Me![CargoTallyID] = Null
End If
End Sub

Both these codes work great when used individually, however because the
“Location†afterupdate event will trigger both I need to to combine them into
one please help.
 
M

Marshall Barton

Levans said:
Code (1) Created by wizard to refresh the “Location” combobox
Private Sub Location_AfterUpdate()
On Error GoTo Err_Refresh__Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

Exit_Refresh__Click:
Exit Sub

Err_Refresh__Click:
MsgBox Err.Description
Resume Exit_Refresh__Click
End If
End Sub

Code (2)
Private Sub Location_AfterUpdate()
If Not IsNull(Me![Location]) Then
Me![CargoTallyID] = [Forms]![CargoTallyfrm].[CargoTallyID]
ElseIf IsNull(Me![Location]) Then
Me![CargoTallyID] = Null
End If
End Sub

Both these codes work great when used individually, however because the
“Location” afterupdate event will trigger both I need to to combine them into
one please help.


I can't rememberwhat that archaic A2 wizard code is doing, a
"Refresh"?

Although I don't understand why you think you need to
"refresh" the combo box, I think you might want to add:
Me.Location.Requery
to the end of your second procedure.
 
G

Guest

Hi Marshall,

Yes that code is to refresh the FORM once the "Location" combo has been
updated.
Is refresh and requety the same?

So I can replace all that refresh code with the short requery code?

Marshall Barton said:
Levans said:
Code (1) Created by wizard to refresh the “Location†combobox
Private Sub Location_AfterUpdate()
On Error GoTo Err_Refresh__Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

Exit_Refresh__Click:
Exit Sub

Err_Refresh__Click:
MsgBox Err.Description
Resume Exit_Refresh__Click
End If
End Sub

Code (2)
Private Sub Location_AfterUpdate()
If Not IsNull(Me![Location]) Then
Me![CargoTallyID] = [Forms]![CargoTallyfrm].[CargoTallyID]
ElseIf IsNull(Me![Location]) Then
Me![CargoTallyID] = Null
End If
End Sub

Both these codes work great when used individually, however because the
“Location†afterupdate event will trigger both I need to to combine them into
one please help.


I can't rememberwhat that archaic A2 wizard code is doing, a
"Refresh"?

Although I don't understand why you think you need to
"refresh" the combo box, I think you might want to add:
Me.Location.Requery
to the end of your second procedure.
 
M

Marshall Barton

Ahh yes, "refresh" the form, not the combo box. In this
case the line of code should be:
Me.Requery

What I had before would just "refresh" the combo box, which
wasn't what you wanted. Sorry if the right answer is even
shorter than the wrong answer ;-)

Note that the wizard generated code is really only doing
that one thing. The rest of the code was just the standard
error handling code that should be included in every
procedure.

The Requery method reloads all of the form's data from its
record source query. Refresh only checks if any of the
form's records were modified by another user. Modified
records will be refreshed, deleted records will show in the
form as "Deleted", but new records will not be included in
the refreshed dataset. Bottom line, Refresh is rarely
useful. OTOH, Requery is very popular, especially if the
form's record source query's criteria is changed (which I
suspect is the purpose of the combo box).
--
Marsh
MVP [MS Access]


Levans digital wrote:\
Yes that code is to refresh the FORM once the "Location" combo has been
updated.
Is refresh and requety the same?

So I can replace all that refresh code with the short requery code?

Marshall Barton said:
Levans said:
Code (1) Created by wizard to refresh the “Location” combobox
Private Sub Location_AfterUpdate()
On Error GoTo Err_Refresh__Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

Exit_Refresh__Click:
Exit Sub

Err_Refresh__Click:
MsgBox Err.Description
Resume Exit_Refresh__Click
End If
End Sub

Code (2)
Private Sub Location_AfterUpdate()
If Not IsNull(Me![Location]) Then
Me![CargoTallyID] = [Forms]![CargoTallyfrm].[CargoTallyID]
ElseIf IsNull(Me![Location]) Then
Me![CargoTallyID] = Null
End If
End Sub

Both these codes work great when used individually, however because the
“Location” afterupdate event will trigger both I need to to combine them into
one please help.


I can't rememberwhat that archaic A2 wizard code is doing, a
"Refresh"?

Although I don't understand why you think you need to
"refresh" the combo box, I think you might want to add:
Me.Location.Requery
to the end of your second procedure.
 
G

Guest

Ahh Marshall,

Sorry for late response but my computer was down. I tried your suggestions
and yes you are so correctl it works the way I wanted it.

Thanks very much.

I posted the following question previously but would like a second opinion
on it.

I have a Main Invoice Form (InvoiceFrm) and Subform (InvoiceDetailsFrm)
The subform which is continuous has a checkbox "Delivered" on each line item
to Make 3 additional fields "Land", "Water", and "Air" Visible/Not Visible.
It works. However instead of showing/hiding only these fields on that
specific line item it show/hide all line items in the subform.

What can I do to fix this please help!


Marshall Barton said:
Ahh yes, "refresh" the form, not the combo box. In this
case the line of code should be:
Me.Requery

What I had before would just "refresh" the combo box, which
wasn't what you wanted. Sorry if the right answer is even
shorter than the wrong answer ;-)

Note that the wizard generated code is really only doing
that one thing. The rest of the code was just the standard
error handling code that should be included in every
procedure.

The Requery method reloads all of the form's data from its
record source query. Refresh only checks if any of the
form's records were modified by another user. Modified
records will be refreshed, deleted records will show in the
form as "Deleted", but new records will not be included in
the refreshed dataset. Bottom line, Refresh is rarely
useful. OTOH, Requery is very popular, especially if the
form's record source query's criteria is changed (which I
suspect is the purpose of the combo box).
--
Marsh
MVP [MS Access]


Levans digital wrote:\
Yes that code is to refresh the FORM once the "Location" combo has been
updated.
Is refresh and requety the same?

So I can replace all that refresh code with the short requery code?

Marshall Barton said:
Levans digital wrote:

Code (1) Created by wizard to refresh the “Location†combobox
Private Sub Location_AfterUpdate()
On Error GoTo Err_Refresh__Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

Exit_Refresh__Click:
Exit Sub

Err_Refresh__Click:
MsgBox Err.Description
Resume Exit_Refresh__Click
End If
End Sub

Code (2)
Private Sub Location_AfterUpdate()
If Not IsNull(Me![Location]) Then
Me![CargoTallyID] = [Forms]![CargoTallyfrm].[CargoTallyID]
ElseIf IsNull(Me![Location]) Then
Me![CargoTallyID] = Null
End If
End Sub

Both these codes work great when used individually, however because the
“Location†afterupdate event will trigger both I need to to combine them into
one please help.


I can't rememberwhat that archaic A2 wizard code is doing, a
"Refresh"?

Although I don't understand why you think you need to
"refresh" the combo box, I think you might want to add:
Me.Location.Requery
to the end of your second procedure.
 
M

Marshall Barton

Levans said:
I posted the following question previously but would like a second opinion
on it.

I have a Main Invoice Form (InvoiceFrm) and Subform (InvoiceDetailsFrm)
The subform which is continuous has a checkbox "Delivered" on each line item
to Make 3 additional fields "Land", "Water", and "Air" Visible/Not Visible.
It works. However instead of showing/hiding only these fields on that
specific line item it show/hide all line items in the subform.

What can I do to fix this please help!


You can not "fix" that. Since there is only one of each
control, any control property you set applies to all copies
of the control. The best approach to this kind of situation
is to use Conditional Formatting to change the color of the
three controls or to enable/disable them.

If these three controls are stacked one on top of another so
it appears as if there's only one control, then you could
add another text box on top of all of them. This additional
text box can use an expression with IIf function to
determine which value to display.
 

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