Problem with simplifing code

snagrat

Registered User.
Local time
Today, 17:21
Joined
Apr 2, 2002
Messages
61
I have the following code:


With CodeContextObject
.cboPostCode.Visible = False
.cmdGrout.Visible = True
.cmdAddTileProduct.Visible = True
.txtCustomerID.Visible = True
.txtSurname.Visible = True
DoCmd.GoToControl "txtSurname"
DoCmd.FindRecord .lstDetails, acEntire, False, , False, acCurrent, True
DoCmd.GoToControl "txtCustomerID"
DoCmd.FindRecord .lstDetails, acEntire, False, , False, acCurrent, True
.lstDetails.Visible = False
End With

I am trying to edit it so I get rid of all the DoCmd in the middle and came up with this coding


With CodeContextObject
.cboPostCode.Visible = False
.cmdGrout.Visible = True
.cmdAddTileProduct.Visible = True
.txtCustomerID.Visible = True
.txtSurname.Visible = True
With DoCmd
.GoToControl "txtSurname"
.FindRecord .lstDetails, acEntire, False, , False, acCurrent, True
.GoToControl "txtCustomerID"
.FindRecord .lstDetails, acEntire, False, , False, acCurrent, True
End With
.lstDetails.Visible = False
End With
However by doing this I get an error on this line:

.FindRecord .lstDetails, acEntire, False, , False, acCurrent, True

Where have I gone wrong?
 
Does anyone know or do you all think it should work?

I can't see why it sholdn't
 
The DoCmd is not an object. You can't use the With statement on the Docmd.

This ought to work:

With CodeContextObject
.cboPostCode.Visible = False
.cmdGrout.Visible = True
.cmdAddTileProduct.Visible = True
.txtCustomerID.Visible = True
.txtSurname.Visible = True
lstDetails.Visible = False
End With
DoCmd.GoToControl "txtSurname"
DoCmd.FindRecord .lstDetails, acEntire, False, , False, acCurrent, True
DoCmd.GoToControl "txtCustomerID"
DoCmd.FindRecord .lstDetails, acEntire, False, , False, acCurrent, True

HTH
 
Well what you have suggested does not work

The only code that works is the first code I posted, the code that was created from the macro when I converted it into a module

It may not be possible but I would like to simplify it really
 

Users who are viewing this thread

Back
Top Bottom