Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Auto Insert a field into the current record ACCESS 2007 VBA

Posted on 2013-01-10
3
Medium Priority
?
581 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
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 …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

715 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