Solved

Auto Insert a field into the current record ACCESS 2007 VBA

Posted on 2013-01-10
3
537 Views
Last Modified: 2013-01-10
Hi,

I'm using this function which tells you the machine name/number of user.

Function fOSMachineName() As String
'Returns the computername
Dim lngLen As Long, lngX As Long
Dim strCompName As String
    lngLen = 16
    strCompName = String$(lngLen, 0)
    lngX = apiGetComputerName(strCompName, lngLen)
    If lngX <> 0 Then
        fOSMachineName = Left$(strCompName, lngLen)
    Else
        fOSMachineName = ""
    End If
End Function


The function works fine, it's for ref.

Here is the issue:

I have a notes system where users can add notes to accounts.

Table Name : Sup_Notes
Field Names :
ID(Auto)
Supplier_Code(Text)
Date_Time (date/time)
Notes (memo)
Machine_Number (Text)

I would like to know how I could add an event which will insert the machine_number for the current record being entered?

So the user loads the form, writes a note, the date already populates from =now() in default value setting, and also the user =fosmachinename is inserted to this record only.

 Any help appreciated?

Kind regards,

Rich
0
Comment
Question by:squidlings
  • 2
3 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 38763414
Use the current event of your form to check for a new record:

Private Sub Form_Current()
        If Me.NewRecord = true then
                 Me.MachineNumber = fosmachinename 
        end if
end sub

Open in new window

0
 

Author Comment

by:squidlings
ID: 38763454
wow, easy as that...

I actually think I'm pretty good and putting Access DB's together, but my head doesn't code like you guys.  This basic stuff and I can't figure it myself :(

Massive thanks!

Rich
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38763478
You're welcome!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now