Wrong data (1 Viewer)

John Sh

Member
Local time
Today, 22:41
Joined
Feb 8, 2021
Messages
408
I have a small form with four controls, each bound to a field in a table.
The table has various fields holding publicly available information as well as the four fields that hold private information. This all on a single record.
To access the private info requires a double click on a particular control or click the "New" button.
Regardless of what record I select, the secondary form opens with info in the first non-null record. This happens to be the second record in the table.
The form itself is bound to the common table.
The code for the form is:
Code:
Option Compare Database
Option Explicit

Private Sub btnNoInfo_Click()
    isNew = False
    DoCmd.Close acForm, Me.Name
End Sub

Private Sub Form_Load()
    If isNew = True Then
        Me.btnClose.Visible = False
        Me.btnNoInfo.Visible = True
    Else
        Me.btnClose.Visible = True
        Me.btnNoInfo.Visible = False
    End If
End Sub
The calling code is:
Code:
Private Sub BtnNew_Click()
    isNew = True
    DoCmd.Close acForm, "nok"
    Me.Dirty = False
    Call locker(False)
    DoCmd.GoToRecord , , acNewRec
    Call show("Please enter data in all relevant fields", "Y", 2)
    Me.txtNameInit.SetFocus
End Sub

Public boolean isNew flags a new record.
Screenshot_43.jpg
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:41
Joined
Feb 19, 2002
Messages
43,223
Is IsNew a public function that you wrote? What is it checking? Most of the code makes no sense. The code in your load event looks like code that belongs in the form's Current event. In that event, if you were trying to control which controls were visible depending on whether or not the record is new, you wouldn't use a custom function, you would use the NewRecord property.
Code:
Private Sub Form_Current()
    If Me.NewRecord = True Then
        Me.btnClose.Visible = False
        Me.btnNoInfo.Visible = True
    Else
        Me.btnClose.Visible = True
        Me.btnNoInfo.Visible = False
    End If
End Sub
The load event would only ever see the first record. Toggling the visible property probably needs to happen for every record you view.

Locker() also seems to be a function whose purpose is murky.

The message in red on the picture of the form doesn't make sense either since there is no control that lets someone select anything. That functionality is accomplished with a combo, listbox, or option group and the form doesn't have any of these.

I don't see any code that opens another form. To open a form to a specific record, you need to use the where argument of the OpenForm method.

Telling people to enter data in all relevant fields isn't validation code and will not prevent the user from leaving all fields empty or putting invalid data in a field. For example, phone numbers only have numeric characters. Area codes can be validated if you want to go that far. eMail has rules also. For example, there is always an @ somewhere and the email address does not allow spaces and certain special characters.
 
Last edited:

Isaac

Lifelong Learner
Local time
Today, 05:41
Joined
Mar 14, 2017
Messages
8,774
Or do you mean IsNew to be a variable, in which case, please please please stop everything you're doing and learn about option explicit, variables, and typing (at least the basic principles) before trying any more development
 

John Sh

Member
Local time
Today, 22:41
Joined
Feb 8, 2021
Messages
408
Isaac> If you read my post you would see that "isNew" is, in fact, a public boolean variable. More to the point please answer my question.
Pat> You seem to have a propensity for pulling peoples code to bits without attempting to answer the question. As a"super moderator" one would expect better things from you. I have stated many times on this forum that I am a novice programmer and am here for help. Your responses are far from helpful and border on being degrading.
That said, you may have inadvertantly pointed me in the right direction. For that I thank you.
John
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:41
Joined
Feb 19, 2002
Messages
43,223
That said, you may have inadvertantly pointed me in the right direction. For that I thank you.
Since my help is not welcome, in the future feel free to help yourself.
 

Users who are viewing this thread

Top Bottom