New record not staying selected (1 Viewer)

Kraj

Registered User.
Local time
Today, 17:17
Joined
Aug 20, 2001
Messages
1,470
I have a very minor but annoying bug. My code grabs some information from the current record and passes it to a new record, then hides and shows some buttons and instruction labels. The strange thing is that when it is done I can't edit any fields until I click on the record selector button, which I don't even want on the form. It's an unintuitive and annoying extra click; I'm not sure exactly why it's happening and haven't found any simple operation to mimic clicking the record selector. Any ideas would be appreciated.

Code:
Private Sub cmdNewFeeNextStep_Click()

' These variables will carry the value for the type of fee into the new record

Dim varFeeDescription, varMethod As String

DoCmd.Save

varFeeDescription = Me!FeeDescription

If Len(Me.Method & vbNullString) > 0 Then
varMethod = Me!Method
End If

'The IF statements above and below tell Access to ignore the Method field if it's blank.

DoCmd.GoToRecord , frmFeeScheduleUpdate, acNewRec

Me!FeeDescription = varFeeDescription
If Len(varMethod) > 0 Then
Me!Method = varMethod
End If

' We now have a new record for the same combination of fee type and method.
' The next sections unlock fields for editing and displays or hides instruction labels and navigation buttons.

Me!FeeAmount.Locked = False
Me!FeeStartDate.Locked = False

Me!FeeAmount.SetFocus

lblInstruction1.Visible = False
lblInstruction2.Visible = False
lblInstructions4.Visible = False
FeeEndDate.Visible = False
cmdNewFeeNextStep.Visible = False
cmdQuitNoSave.Visible = False
cmdDiscontinueFee.Visible = False
lblInstruction3.Visible = True
cmdFinishNewFee.Visible = True


End Sub
 

jdraw

Super Moderator
Staff member
Local time
Today, 12:17
Joined
Jan 23, 2006
Messages
15,383
I'm not sure how to resolve your issue, but I did notice something.

This line does NOT do what you think it does -
Dim varFeeDescription, varMethod As String
.

In Access you must explicitly dim your variables. If you do not, they will default to Variants.

In your case -
varFeeDescription will be a Variant
varMethod will be a String data type.

You can say
Dim varFeeDescription as String, varMethod As String
OR
Dim varFeeDescription As String
Dim varMethod As String
 

boblarson

Smeghead
Local time
Today, 09:17
Joined
Jan 12, 2001
Messages
32,059
And as a side note, I wouldn't use varMethod, since it is declared as a string and not a variant. I would use

Dim strMethod As String
Dim strFeeDescription As String

instead of making it a variant.
 

Kraj

Registered User.
Local time
Today, 17:17
Joined
Aug 20, 2001
Messages
1,470
Good to know :)

Like most terrible programmers, I start with what I know and then hack and slash code salad together until it works. These suggestions will help me be tidier.

So now I'm sad that even Bob Larson doesn't have a suggested fix for this weirdness, but happy that I'm not just an ignoramus who didn't know the obvious problem. :D
 

boblarson

Smeghead
Local time
Today, 09:17
Joined
Jan 12, 2001
Messages
32,059
1. Have you tried moving the focus last:

Me!FeeAmount.SetFocus

AFTER the other code bits? And also you should preface those other code bits with

Me.

like
Me.lblInstruction1.Visible = False

so it is more explicit and Access can be sure of what you are referencing.
 

Kraj

Registered User.
Local time
Today, 17:17
Joined
Aug 20, 2001
Messages
1,470
One of the controls I'm hiding is the button that executes the code, so it has the focus at the time I'd try to hide it, which I cannot do. The only real purpose of setting the focus is to allow "cmdNewFeeNextStep.Visible = False" to work.

Also, if I remove all the code after the IF statements the same problem is there, so it would appear the issue is occuring before any focus change.
 

AccessMSSQL

Seasoned Programmer-ette
Local time
Today, 09:17
Joined
May 3, 2012
Messages
636
After the last line: cmdFinishNewFee.Visible = True
try this:

DoCmd.RunCommand acCmdSelectRecord

OR if you don't have any required fields in the table try this:

me.refresh
 
Last edited:

Kraj

Registered User.
Local time
Today, 17:17
Joined
Aug 20, 2001
Messages
1,470
DoCmd.RunCommand acCmdSelectRecord

That did the trick! Interestingly, the record selector button does not appear 'pressed' by this code, but the record is still selected and editable. Thank you kindly!
 

Users who are viewing this thread

Top Bottom