Re: add new record and set value

S

Steve Schapel

DeVille,

You did not mention what the problem is. Did your macro fail?

In any case, I would advise against this approach, which is an
irregular way to go about such a thing. Is there any reason why you
can't simply base your form directly on the table, and use your form
for data entry?

- Steve Schapel, Microsoft Access MVP
 
D

DeVille

Thanks for your response, yes that would make things
easier it is true, but the problem is we are using the
database to log helpdesk calls so speed is very important
I would really like the users to be able to stay in the
same form. Also The parent table is not the customer
table as you might expect, only some of the callers give
us their name, so we work from a RefID and then search
for existing callers details by typing the name in the
Text Box 'Forms!EntryForm1!CustomerName' and then link
them to the main Reference table or if they have never
rang before we create a new customer which is what I am
trying to do with this action

I have changed the macro a bit since the last post
It works up to the (?), it opens the table
(ContactDetailsTable), goes to a new record, goes to the
right field (CustomerName) then fails to change set the
value to the vale in the text box 'Forms!EntryForm1!
CustomerName'

Function Add_Name()
On Error GoTo Add_Name_Err

With CodeContextObject
DoCmd.OpenTable "ContactDetailsTable",
acViewNormal, acEdit
DoCmd.GoToRecord acTable, "ContactDetailsTable",
acNewRec
DoCmd.GoToControl "CustomerName"
(?)"CustomerName" = Forms!EntryForm1!CustomerName
End With


Add_Name_Exit:
Exit Function

Add_Name_Err:
MsgBox Error$
Resume Add_Name_Exit

End Function


-----Original Message-----
DeVille,

You did not mention what the problem is. Did your macro fail?

In any case, I would advise against this approach, which is an
irregular way to go about such a thing. Is there any reason why you
can't simply base your form directly on the table, and use your form
for data entry?

- Steve Schapel, Microsoft Access MVP


Hi
I am trying to create a new records in my 'Contact
Details' table every time I run a macro called 'Add
Name', the macro is supposed to take the data from a text
box called 'CustomerName' (on my form) 'EntryForm1' and
then open the 'Contact Details' table, add a new record
go to the 'CustomerName' field in the table and set the
value to be the same as the text box
called 'CustomerName' (on form), I am new to this so I
have converted the macro into code, if any one can help
thanks in advance

Function Add_Name()
On Error GoTo Add_Name_Err

With CodeContextObject
DoCmd.OpenTable "Contact Details", acViewNormal,
acAdd
DoCmd.GoToRecord acTable, "Contact Details",
acNewRec
DoCmd.GoToControl "CustomerName"
.[Contact Details]!CustomerName = Forms!
EntryForm1!CustomerName
End With


Add_Name_Exit:
Exit Function

Add_Name_Err:
MsgBox Error$
Resume Add_Name_Exit

End Function

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top