Adding Record With Field From Another Form, Access 2007

mrsgwen

Registered User.
Local time
Today, 09:38
Joined
Dec 9, 2008
Messages
26
:confused: Ok, let me try to explain my delima....

I have a form with several text boxes and combo boxes. One of the fields (ServiceID) is picked up from another form.
There record source is a query with the following fields: CartID, ServiceID, SerialNbr, CartStatus, CartStatusDate, CartEvent, CartRepairType, CartEventSubType and CartRemarks. The ServiceID field has a Criteria of Forms!Services!ServiceID

I want to be able to use the navigation buttons built in Access to navigate and add a new record. Now I click the add new record button from the navigation buttons a fields are blank for data entry which is good. The thing is the ServiceID field is blank too so how do I get it to write table because I don't want the user to actually type in the ServiceID. when I click the add new record button every field should be blank except for the ServiceID which was brought over from another form.

I hope I have explained this ok
 
Sounds like you want to put a reference to the other form in the default value property of the ServiceID control on this form. You should be able to use the Build feature.
 
worked Like a charm pbaldy.....thank you so much for your help!
 
oh and one more thing.

If I want to add the current date and user to the table as well, how would I do that being that I'm using access built in navigation controls. Because at first I had it behind the addrec button using code. I have 2 fields in the table to hold the values called Timestamp and UserID
 
If those fields are on the form (they can be hidden), you can also set their default value properties. Not sure where you're getting the user, but you should be able to use the same method you used in code. You can use Date() for the current date or Now() for the current date and time.
 
for Timestamp will I put Now() as the ControlSource?

as for the user name I was using code to capture that which is the user that is logged in at the time.
 
Not the control source, the default value. If you put it in the control source, it will display it but not save it.
 
ok it work for the Timestamp but as for the UserID here is the code I had
Public Function UserName() As String
Dim sBuffer As String
Dim lSize As Long
Dim strAppUser As String
UserName = ""
sBuffer = Space$(40)
lSize = Len(sBuffer)
Call GetUserName(sBuffer, lSize)
strAppUser = Left(sBuffer, InStr(sBuffer, Chr(0)) - 1)
UserName = strAppUser
End Function


and I put this code at the top of all the code

Public appUser As String
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As Long) As Long

But I'm sure I can't put all this code in the default value property.

so how do I capture it?
 
Try this as a default value:

=UserName()
 
Dang you are good!!!!

that did it! 'preciate it sooooo much!
 

Users who are viewing this thread

Back
Top Bottom