Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems getting default value to appear in form correctly 1

Status
Not open for further replies.

yogi71

Technical User
Apr 5, 2013
13
0
0
US
Using Access 2010 (64bit) on Windows 7 64-bit

I have a form with two fields in it.
The first is WeekEndDate.

For the default value, I put [highlight #3465A4]=Date()+(7-Weekday(Date()))[/highlight] with the expectation of opening the form and seeing Today's Weekending Date. Instead, I get the date that was in the field last time the form was open.
What am I missing here?

The second is Name.
The Control Source for this field is Name from tblPeople. It is a dropdown list where you can pick the name of the person. It is bound to column 1, which is your Windows Login field. I want it to default to the person using the computer. I have a module
Code:
Private Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
    strUserName = String$(254, 0)
    lngLen = 255
    lngX = apiGetUserName(strUserName, lngLen)
    If (lngX > 0) Then
        fOSUserName = Left$(strUserName, lngLen - 1)
    Else
        fOSUserName = vbNullString
    End If
End Function
'******************** Code End **************************

I set the Default Value to the form field to =fOSUserName()

Everytime I open the form, it returns the name of the person selected last time the form was opened. What am I missing here?
 
you could try adding either
me.refresh
or
me.requery
into the onload event of the form, or after you do the call to the function.

'Clever boy...'
 
Are there any other suggestions, I'm having no luck with this one...
 
Are the text boxes with the default value bound to fields of a table?
When you open the form, are you looking at a new or existing record?

Both expressions worked for me in Access 2007.



Duane
Hook'D on Access
MS Access MVP
 
The Name field is a ComboBox bound to a field in a table.

The Date field is a Text box and is unbound.

When the form opens, it lists the last person picked from the Name field and the last date used.
I was hoping to automate it to make it easier to use (my userbase is very un-technical), but if I have to make them pick their name, I can.
 
The date field started working after I rebooted my computer. Not sure what that was all about.
At least I know I did it right.

You answered the question for why the Name field wasn't working as expected.
I have since made a change to the way things work, and now it works as designed as well. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top