Newbie needs help

pepegot

Registered User.
Local time
Today, 05:23
Joined
Feb 20, 2006
Messages
39
I have to learn the correct syntax for this, as I think it should work to place a zero in front of the address number. Please advise

Private Sub Address_Click()
Dim Add As String
Dim Length As String

Add = Val([Address])
Length = Len(Add)
IIF(Length =3,"0"+"[Address]","[Address]")
End If

Is there DoCmd missing?
P.S. Where can I get a good book that explains, rather than throws out at you, the syntax?
 
Dim Add As String
Dim Length As Integer

Add = Val([Address])
Length = Len(Add)

Me.[Address] = IIF(Length =3,"0" & "[Address]","[Address]")


IIF() is a one-liner, no need for "End If". needs a recipient for the result
Lenght data type, was wrong
Concatenate with "&", not "+" (prefered)
 
Placed the code you gave into the following, but no result. Question of position?

Private Sub Save_Click()

Dim Add As String
Dim Length As Integer
Add = Val([Address])
Length = Len(Add)
Me.Address = IIf(Length = 3, "0" & "[Address]", "[Address]")

On Error GoTo Err_Save_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit_Save_Click:
Exit Sub

Err_Save_Click:
MsgBox Err.Description
Resume Exit_Save_Click



End Sub
 
Hi,
As to position of code it depends what event you want to trigger the change of address, but I think you may need to remove the quotes around [Address] so your iif statement reads as follows

Code:
Me.[Address] = IIF(Length =3,"0" & [Address],[Address])

Hope this helps.

Jubb
 
I did what you suggested and removed the Quotes and it worked fine.

Thank you and all the others on this helpful Forum!

I need to learn to fish-not just copy. The Access manuals, with VBA, are not good. At least, I have not found one yet. Microsoft help, on the web, is scattered all over the place. There must be some literature that explains the uses of On Click, etc. and the acform etc. and the structure. I know what needs to be done, but I lack the structure to do it. The code is not difficult, just well scattered. I was a pretty good FoxPro Designer in the old days. When I was working, I had access to the MIS Dept.-no problems. As I am retired and designing Databases for my community, I need to learn Basic VBA and some SQL too, so that I can transfer the ideas from my mind to the code.
Any suggestions on literature will be appreciated. Most Access books explain the obvious and omit the particulars.

Thanks again for your help
 
...can't believe, I left the quotes in!
 

Users who are viewing this thread

Back
Top Bottom