Select to view content in your preferred language

Pre-Populating Fields with system info (Username and Date)

3814
2
Jump to solution
01-06-2014 12:30 PM
MicahWilliamson
Occasional Contributor II
Greetings all:

I am using VBScript to pre-populate a few fields of a point shapefile whether they are new, or edited By a user.
I have an edit form and one page with two fields (trying to keep it simple while I get it working).

Using the onload event of the edit form, I'm adding this VB:

Dim objNetwork
Dim userName
Dim MyDate
Set objNetwork = CreateObject("WScript.Network")
userName = objNetwork.UserName
MyDate = Now()
ThisEvent.Object.pages("PAGE1").controls("USER").Value = userName
ThisEvent.Object.pages("PAGE1").controls("DATE").Value = MyDate

This populates the USER box with the user's login name, (works great). But it does not populate the DATE field with anything
Infact i get an "Object not Defined" error for that line 8. if I swap the last two lines the DATE field gets populated but the USER field does not.

This leads me to assume it must be some limitation with the VB that cannot populate two boxes on the same event....?
So, I tried putting similar code onto the PAGE1 'onload' event but could not figure out the call. In fact I tried to make it very simple and just pre-populate the field with a fake user name text string:

ThisEvent.Object.controls("USER").Value = "Frank"

None of them work, no error just doesn't work. I'm at a loss. Arcpad's help documentation is for 10.0 and doesn't really help put the pieces together anyway.
Tags (3)
0 Kudos
1 Solution

Accepted Solutions
HannahFerrier
Regular Contributor
Hi Micah,

This was such a common request from ArcPad Users that ArcPad 10.2 now includes a new feature called Quick Fields.

The idea behind Quick Fields is that you can select your own 'rules' using the ArcPad Expression Builder to populate your fields when you create new features. You can choose from the date and time, x and y coordinates, incremental ID's, names and much more. You simply select the field name you want to apply the rule to, then select the value from the drop-down list (or even write your own).

Simply follow these instructions to build your first Quick Fields Expression!

Let me if you need anything more,

Hannah 🙂

View solution in original post

0 Kudos
2 Replies
HannahFerrier
Regular Contributor
Hi Micah,

This was such a common request from ArcPad Users that ArcPad 10.2 now includes a new feature called Quick Fields.

The idea behind Quick Fields is that you can select your own 'rules' using the ArcPad Expression Builder to populate your fields when you create new features. You can choose from the date and time, x and y coordinates, incremental ID's, names and much more. You simply select the field name you want to apply the rule to, then select the value from the drop-down list (or even write your own).

Simply follow these instructions to build your first Quick Fields Expression!

Let me if you need anything more,

Hannah 🙂
0 Kudos
MicahWilliamson
Occasional Contributor II
Thanks for the reply Hannah.
I have already looked into The Quick Fields. It is a great way to add updates to new features created within ArcPad. However, it does not serve the purpose to pre-populate these fields on a feature edit rather than just creating new features.

All that being said I did figure out the code and will paste it below:

Sub SetDateCPU
[INDENT] Dim pCtrl1, pPages1, MyDate, pCtrl2, objNetwork, cpuName
Set pPages1 = ThisEvent.Object.Pages("PAGE1")
Set pCtrl1 = pPages1.Controls("MY_DATE") ' Your Date field here
' **If the below field is a text field the following works - if it's a date field just call Now()**
        MyDate = MONTH(Date())&"/"& DAY(Date())&"/"& YEAR(Date())
pCtrl1.Value = MyDate
Set pCtrl2 = pPages1.Controls("USERNAME") ' Your username Field Here
Set objNetwork = CreateObject("WScript.Network")
UName = objNetwork.UserName
pCtrl2.Value = UName[/INDENT]
End Sub


Of course you don't need the subs if you don't put it into a VB. I dropped this into a "onLoad" action of the edit form. Works like a champ!

Note** this calls the Microsoft WScript Object exe, so there's Windows environment variables that you could call into the script (Domain, CPU Name, IPaddress, etc...)