By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,775 Members | 1,399 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,775 IT Pros & Developers. It's quick & easy.

Changing form defaults based on form values...

P: 22
Hi, I'm a beginner to Access so this question may seem pretty simple to some of you, but I could not seem to find an answer elsewhere on the web. I have a form which allows the user to select two variables - shift number and supervisor. When this form is submitted it opens another form, in which I would like the default values of fields 'Shift' and 'Supervisor' to be the variables entered in the original form. Therefore, the default values would be changed based on what the user selects. Could someone explain how to do this?

Thanks....
Oct 30 '06 #1
Share this Question
Share on Google+
7 Replies


100+
P: 143
I would use the OpenArgs method. There is a very good example of passing parameters on this site.

http://fmsinc.com/free/newtips/access/accesstip13.asp
Oct 30 '06 #2

P: 22
Hmm... thanks Tanis, but I seem to be getting an error using the code provided there. For some reason the debugger does not like this line:

If Me.Len(OpenArgs) > 0

It highlights the ".Len" as an error. Not sure what that's all about, as I inserted the OpenArgs function as instructed.....
Oct 30 '06 #3

100+
P: 143
Should be

If Len(Me.OpenArgs) > 0
Oct 30 '06 #4

NeoPa
Expert Mod 15k+
P: 31,489
Try
Expand|Select|Wrap|Line Numbers
  1. If Len(Me.OpenArgs) > 0 Then
Oct 30 '06 #5

P: 22
Thanks again, it's working now (sorry, I forgot to include the 'Then' in my earlier paste).

Just one more question about this if I can... How can I pass multiple variables using this OpenArgs function? As mentioned, I have 'Shift' and 'Supervisor' values that I'd like to pass to the form. However, the example seems to only deal with one. Is there a way to expand the OpenArgs to include both values?
Oct 30 '06 #6

NeoPa
Expert Mod 15k+
P: 31,489
You could assign a string with values separated by your own designated separator character. I typically use a '|' or a ';' as I want to make it unlikely that any of the data contains the character normally.
In the OnOpen event of the called form, you can handle extracting the values you want from the string passed.

I have to admit that I was unaware of this feature so, many thanks to Tanis for bringing it to my attention.
Oct 30 '06 #7

P: 22
Yes, thanks to both of you for all your help. I've noticed that the current code just sets the default value for the one record, and not on any subsequent records. Since I'm in datasheet mode, I'd like each new row to have that default value. I tried inserting this code in the OnLoad event of the form (within the code provided above), but it did not seem to work:

Me.Supervisor.DefaultValue = strValue

Here's the whole thing:


Expand|Select|Wrap|Line Numbers
  1.  Private Sub Form_Load()
  2.  
  3.       Dim intPos As Integer 'Position of the Pipe
  4.       Dim strControlName As String 'Controlname passed
  5.       Dim strValue As String 'Value to assign
  6.  
  7.       If Len(Me.OpenArgs) > 0 Then
  8.  
  9.         intPos = InStr(Me.OpenArgs, "|")
  10.  
  11.         If intPos > 0 Then
  12.  
  13.           'Retrieve Control Name
  14.           strControlName = Left$(Me.OpenArgs, intPos - 1)
  15.  
  16.           'Retrieve Value to Assign
  17.           strValue = Mid$(Me.OpenArgs, intPos + 1)
  18.  
  19.             'Make the Assignment
  20.  
  21.           Me.Supervisor.DefaultValue = strValue
  22.  
  23.         End If
  24.  
  25.       End If
  26.  
  27.  
  28.  
  29.     End Sub
Oct 31 '06 #8

Post your reply

Sign in to post your reply or Sign up for a free account.