My Assistant
![]() ![]() |
|
|
Nov 14 2009, 07:31 PM
Post
#1
|
|
|
UtterAccess Veteran Posts: 315 From: CA |
Hey UA. I'm using the Security Demo code I found on this forum for user access in my current project. I have a form that, when a new record is entered, captures the data from the global gSecurityID.
So the code looks like this: CODE Private Sub Form_Current() If Me.NewRecord Then Me.cmbFkAssociateID.Value = getGlobal("gSecurityID") Else 'Do nothing End If Me.cmbFkAssociateID.Requery End Sub And on the BeforeUpdate, like this: CODE Private Sub Form_BeforeUpdate(Cancel As Integer) However, when I click on a record, a new record is added, even though cmbFkNotesID is blank (violating my BeforeUpdate IF).Dim db As DAO.Database Dim rst As DAO.Recordset Set db = CurrentDb Set rst = db.OpenRecordset("tblAppNotes", dbOpenDynaset) If Me.NewRecord Then If IsNull(Me.cmbFkNotesID) Then Cancel = True ElseIf IsNull(gSecurityID) Then Cancel = True MsgBox "You must be logged on to save Notes.", vbOKOnly, "No username detected" Else ' Do nothing, save End If Else With rst .Edit ![fkAssociateID] = Me.cmbFkAssociateID ![notesDate] = Now() ![fkNotesID] = Me.cmbFkNotesID .Update End With End If End Sub What am I doing to cause this? I've moved the code around a few times, with different results, but something remains offbeat and I don't get the results needed. What I need is: - If a user is adding a new record, capture the user (gSecurityID) in cmbFkAssociateID - If a user is modifying a record, capture that user (gSecurityID) in cmbFkAssociateID - Since it's a continuous form and the last record remain blank, I want that blank row to display the user that is logged on (gSecurityID), not the first value on the table - And for all existing records, obviously use the control's assigned RowSource (<-- this one is working) |
|
|
|
Nov 15 2009, 08:18 AM
Post
#2
|
|
|
UtterAccess Guru Posts: 578 From: Florida, USA |
The logical conclusion is that cmbFkNotesID is not Null! Have you checked that out? For example, if the FkNotesID field is an integer, then it might have a default value of 0; but this column might be hidden (if you are display a description in your combobox, not the underlying ID#), so the combobox display is blank.
Because of such situations, when dealing with comboboxes I prefer to check the ListIndex property rather than the Value property, like this: CODE If Me.cmbFkNotesID.ListIndex = -1 then
Cancel = True |
|
|
|
Nov 15 2009, 10:20 AM
Post
#3
|
|
|
UtterAccess Veteran Posts: 315 From: CA |
Thanks Mark. That seems to do it. However, now it seems that Access is now not recognizing that no one is logged on (gSecurityID has no value). I'll probably switch it from IsNull to If gSsecurityID = 0.
Again, thanks. |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 21st May 2013 - 01:53 AM |