How to change a fields data through VBA

harleyskater

IT Manager
Local time
Today, 13:42
Joined
Oct 29, 2007
Messages
95
The copy part of this code works great but I need to set some fields to a default value after the code has ran.
It will be the current record on the form : )

This is part of some VBA code used to copy the record from the current form to a new record. After those 2 functions have ran I want to change 3 of the fields on the new record. I have tried but I do not know the code. I could use a little help on this if anyone has some free time : ) thank you.


Code:
Function fCopyPO(lngPOID As Long) As Long
    
    Dim lngNewID As Long
    
    'Create copy of parent PO record
    lngNewID = fCopyRecord2("dbo_purchase_orders", lngPOID)

    
    fCopyPO = lngNewID
    
    MsgBox "Copy complete", vbInformation
    
[COLOR="Yellow"]    Me!po_completed = "0"
    Me!po_canceled = "0"
    Me!po_revised = Null[/COLOR]
    
End Function
 
Last edited:
Just curious and have a couple questions

Why would you have a function merely return the value of a function? Shouldn't there be some sort of test of the results of fCopyRecord2?
The name of the function and its arg list suggest you are copying a record to a linked table - not sure this can be done without error? What if the copy was not successfull? Are you counting on Access error traps? Do you have error trapping in fCopyRecord2? Why not make fCopyRecord2 a boolean

Code:
Sub fCopyPO(lngPOID As Long)
Dim szMessage As String

    '    Create copy of parent PO record. 
    If fCopyRecord2("dbo_purchase_orders", lngPOID) Then
        szMessage =  "Copy complete"
        Me.po_completed = "0"
        Me.po_canceled = "0"
        Me.po_revised = ""
    Else
        szMessage = "Copy Failed"
        '    do something that would allow the user to correct the problem
    End If

        MsgBox szMessage, vbInformation
    
End Sub

Not pretty but hope it conveys to you my thoughts
 
This is the error I receive. I had actually tried using ( me.textboxname = "value" ) before.

The copy function works awesome I couldn't tell you a lot about how it works because I didn't write it. But I have been using it for some time now.

Thank you for your help I attached a screenshot of the error "invalid use of the ME Keyword"
 

Attachments

  • VBA-ME-ERROR.JPG
    VBA-ME-ERROR.JPG
    98.7 KB · Views: 152
The 'Me' Keyword is only going to work within the form's code module. You are trying to get there remotely from a standard module. To do that you would have to fully qualify the control like Forms!MyForm.MyControl.Value.

So put your routines in the form's module and try it.

HTH
 
doco! you da' man :)

I kinda feel bad now to bother you though because I just noticed on the access faq's part of the forum the its right there. I tried to use the forums search to find it but it didn't yield many results, I am not sure whats up with that. THANK YOU!!!! your code and explaination worked great, if you ever want to take a look at that copy code its really great, I can private message it to you ;)!!!!!!!!!
The 'Me' Keyword is only going to work within the form's code module. You are trying to get there remotely from a standard module. To do that you would have to fully qualify the control like Forms!MyForm.MyControl.Value.

So put your routines in the form's module and try it.

HTH
 

Users who are viewing this thread

Back
Top Bottom