passing a string to a form name....?

B

bubbadahut

I'm not sure what to ask here, but I am wondering if there is a way to make this work. I have several order forms which require the same info and I
am trying to get the following code to work so that I can just call it from a function for all the forms. What is going on here is, the user is
selecting an order type from a list and opening the corresponding form. All the form names have the same syntax in the name "frm (type ie. RFR, MRO,
etc.) Head" If I can get this code to work, I can use the same code in a function, no matter which order type they choose.


Private Sub cmdSelect_Click()
On Error GoTo cmdSelect_Click_Err

Dim strOrderType As String
Dim frmName As String
strOrderType = Me![Type]

frmName = "frm" & strOrderType & "Head"

DoCmd.SetWarnings False
DoCmd.OpenForm frmName, acNormal, "", "", acAdd, acNormal 'the code works to this point

' this is where it begins to break down, I get the message that access can't find the form "frmName"
' Is there a way to get it to recognize the string "frmName" here?

Forms!frmName.fldOrderDt = Date

Forms!frmName.fldRequisitioner = Forms!frmLogged!txtFullName
DoCmd.RunSQL "UPDATE tblOrderType SET tblOrderType.fldNextNum = [tblOrderType]![fldNextNum]+1 WHERE
(((tblOrderType.fldOrderType)=[Forms]![frmOrderType]![Type]));", 0
Forms!frmName.cmboStatus = "Unissued"
DoCmd.Close acForm, "frmOrderType"
DoCmd.SetWarnings True
End Select


would appreicate any help here :)

thanks
greg
 
A

Albert D. Kallal

Simply use the syntax of:

Change:

Forms!frmName.fldOrderDt = Date

to

forms(frmName)!fldOrderDt = Date
 
B

bubbadahut

thank you for the answer and the speedy reply. I figured it would be either be impossible, or something very simple. I tried using
forms!(frmName).-- but it didn't work. close, but not...

thank you again
greg
 
A

Al Borges

Hi Greg:

(rolling up shirtsleeves... if Albert didn't get it just right, this must be
tough...)

Try-

Dim frmName As String, strOrderType As String

strOrderType = Me![Type]

frmName = Chr(34) & "frm" & strOrderType & "Head" & Chr(34)

DoCmd.SetWarnings False
' test your result
MsgBox frmName
' see- it worked, didn't it? Now, let's see if you things run through
OK...
DoCmd.OpenForm frmName, acNormal, "", "", acAdd, acNormal 'the code works
to this point

Regards,
Al



bubbadahut said:
thank you for the answer and the speedy reply. I figured it would be
either be impossible, or something very simple. I tried using
forms!(frmName).-- but it didn't work. close, but not...

thank you again
greg
 
A

Albert D. Kallal

bubbadahut said:
thank you for the answer and the speedy reply. I figured it would be
either be impossible, or something very simple. I tried using
forms!(frmName).-- but it didn't work. close, but not...


No, I did not suggest the above...you want to use:

forms(frmname)!cmboSttus = "bla bla bla"
 
B

bubbadahut

I was saying that is what "I" tried before asking for
help. What you gave me worked wonderfully. I used:

forms(frmName)! --- which you give me,

thanks again
greg
 
B

bubbdahut

Thanks for the reply. Actually, he did get it right :),
it was just a miscomunication on my part. I was trying to
say that I used/tried
Forms!(frmName).
before I asked for help, and that it was close to the
answer which Albert give me..

greg
-----Original Message-----
Hi Greg:

(rolling up shirtsleeves... if Albert didn't get it just right, this must be
tough...)

Try-

Dim frmName As String, strOrderType As String

strOrderType = Me![Type]

frmName = Chr(34) & "frm" & strOrderType & "Head" & Chr (34)

DoCmd.SetWarnings False
' test your result
MsgBox frmName
' see- it worked, didn't it? Now, let's see if you things run through
OK...
DoCmd.OpenForm frmName, acNormal, "", "", acAdd, acNormal 'the code works
to this point

Regards,
Al



bubbadahut said:
thank you for the answer and the speedy reply. I
figured it would be
either be impossible, or something very simple. I tried using
 

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