ajreynolds General User

Joined: 12 May 2012 Posts: 6
|
Posted: Mon Jul 16, 2012 6:42 pm Post subject: Base macro to update one field when another is updated |
|
|
I'm new to Base and macro programming and was hoping someone might be able to give me a bit of help.
I have a table in Base with a couple of text fields, named Model_Name and Picture_File, and a form which displays the table. What I'm trying to do is set it up so when I enter something in the Model Name field, it automatically populates the File Name field, but only if the Picture_file field is blank. For example, when I create a new record and I enter "P-51 Mustang" in the Model_Name field, I want the Picture_file to be filled out with "C:\Pictures\P-51 Mustang.jpg". It should do this as soon as I move off of the Model_Name field and without having to move off the record. I'm going to have a bunch of other fields in this table which also will need to be filled out, but they won't impact the file name. It also should only do this if the Picture_File field is blank, I don't want it overwriting a value if I've manually entered something.
I've been researching it on the net and I've come up with the following macro:
| Code: | Sub CopyNameToImage
dim oFormCtl as object
dim oModelCtl as object
dim oPictureCtl as object
dim sModelName as String
dim sFileName as String
oFormCtl = ThisComponent.Drawpage.Forms.getByName("MainForm")
oModelCtl = oFormCtl.getColumns.getByName("Model_Name")
oPictureCtl = oFormCtl.getColumns.getByName("Picture_File")
sModelName = oModelCtl.getString
sFileName = oPictureCtl.getString
if sFileName = "" and sModelName <> "" then
sFileName = "file:///C:/Users/Me/Documents/RC/plans/Magazine Index Pictures/" + sModelName + ".jpg"
oPictureCtl.setString(sFileName)
endif
End Sub |
This is triggered by the Text Changed event of the Model_Name field.
Simple enough, but it doesn't quite work. When it gets down the the setString call, it gives the error "Property or method not found: setString". I've been searching the Internet and documentation trying to figure this out. I've tried setString, setText, setValue, Text, CurrentValue, and a bunch of other things that I've seen mentioned, but they all give the same error.
I'm sure it's a simple thing I'm missing. Can anyone help me out?
Thanks. |
|
ajreynolds General User

Joined: 12 May 2012 Posts: 6
|
Posted: Wed Jul 18, 2012 6:29 pm Post subject: |
|
|
After puzzling over this for several days, I finally cobbled something together which seems to work. Andrew Pitonyak's online documents really helped. Here it is in case anyone is interested.
| Code: | Sub CopyNameToImage
dim oFormCtl as object
dim oModelCtl as object
dim oPictureCtl as object
dim sModelName as String
dim sFileName as String
dim lNameCol
oFormCtl = ThisComponent.Drawpage.Forms.getByName("MainForm")
oModelCtl = oFormCtl.getColumns.getByName("Model_Name")
oPictureCtl = oFormCtl.getColumns.getByName("Picture_1")
sModelName = oModelCtl.getString
sFileName = oPictureCtl.getString
lNameCol = oFormCtl.findColumn("Picture_1")
if sFileName = "" and sModelName <> "" then
sFileName = "file:///C:/Users/Me/Documents/RC/plans/Magazine Index Pictures/" + sModelName + ".jpg"
oFormCtl.updateString(lNameCol, sFileName)
endif
End Sub
|
|
|