BASIC runtime error

Hi.

I am not an expert Libre Office Base, but I am trying to do some basic macro, and for some reason I am getting an error every time I click on the only form I have saying that I have a BASIC runtime error. Despite that, the MACRO seems to be doing its job anyhow.

I would appreciate if somebody could give me some advise here

This is the exact error message

  • BASIC runtime error.
    An exception occurred
    Type: com.sun.star.container.NoSuchElementException
    Message: There is no element named ‘Citacion’…

A this is the code

sub S_SelectFile
    oform = thiscomponent.drawpage.forms.MainForm.SubFormCitaciones
    ofpkSelectFile = oform.getbyname("FileSelection")
    sUrl = converttourl(ofpkSelectFile.Text)
    for i = len(sUrl) to 1 step -1
        if mid(sUrl,i,1) = "/" then
             sFile = mid(sUrl, i+1, len(sUrl))
             exit for
        endif
    next i
        rem oform.updatestring(3,sFile)
        oform.updatestring(5,sUrl)
        if oform.isnew then
            oform.insertrow
        else
            oform.updaterow
        endif
end sub

Sub S_insert_url_to_Button
    oform = thiscomponent.drawpage.forms.MainForm.getbyname("SubFormCitaciones")
    oButton = oform.PushButtonCitacion
    oButton.TargetUrl = oform.Columns.getbyname("Citacion").getstring
end sub

By the way. There is a fiels named “Citacion” on the table called “Citaciones”

Regards

Just from a quick glance at this, I think oform.Columns is in the recordset, not the form control. It’s the data in your datasource, not how it is displayed on the screen. And depending on other factors, a recorset might not exist, even when it’s associated control does. Other that that I have no idea what the code is trying to do. A bunch of embedded comments to say what’s going on are sorely lacking. Pls, add code comments and re-submit.

Thanks for your prompt answer. I cheked with your changes and generate other errors.

If you look at the following link, you will see the database file, and the example that I used to creates my macro.

According to the example the following entense is just fine.

oButton.TargetUrl = oform.columns.getbyname("Citacion").getstring

Sorry for all the confusion and apologies for the code and earlier comments. Found the problem and it has nothing to do with the code presented above. If you had not presented the .odb it couldn’t be solved.

The error is generated by a Before record change event on MainForm calling Sub S_insert_url_to_Button. So when the form was first opened and before the first data was loaded, the event occurs and generates the error because nothing is loaded yet. If this event is removed, the error goes away. However, since I don’t know why this event was placed there it is not known what other circumstances it affects. The error does not affect further processing.

A little further checking shows that routine should be called from After record change event.