Solved

Auto Insert a field into the current record ACCESS 2007 VBA

Posted on 2013-01-10
3
576 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

732 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