Solved

Auto Insert a field into the current record ACCESS 2007 VBA

Posted on 2013-01-10
3
568 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

749 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