Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Auto Insert a field into the current record ACCESS 2007 VBA

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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

885 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